var loadTime = 0;
var compTime = 0;
var center, groups, icons, subs, menus;
var ss_menus = JSON.parse(window.localStorage.getItem('backstage-access-permissionList'));
if ($('#scroll').length < 1) {
	$('#config_js').after(
		'<script id="scroll" src="' + site.interUrl + '/js/jquery.nicescroll/jquery.nicescroll.min.js"></script>'
	);
}

var ly = {
	/**
	 *	获取url参数 
	 */
	getUrlParam: function(name) {
		var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)'); //构造一个含有目标参数的正则表达式对象
		var r = window.location.search.substr(1).match(reg); //匹配目标参数
		if (r != null) return decodeURI(r[2]);
		return null; //返回参数值
	},

	/**
	 *	初始化目录数据 
	 */
	getMenuData: function() {
		ly.getMenuType(ss_menus);
	},
	getMenuType: function(m) {
		groups = $.grep(m, function(c) {
			return c.level == 1;
		});
		subs = $.grep(m, function(c) {
			return c.level == 2;
		});
		menus = $.grep(m, function(c) {
			return c.level == 3;
		});
		fours = $.grep(m, function(c) {
			return c.level == 4;
		});
		var groupid = ly.getUrlParam('groupid') || '';
		var subid = ly.getUrlParam('subid') || '';
		var menuid = ly.getUrlParam('menuid') || '';
		var fourid = ly.getUrlParam('fourid') || '';
		ly.getMenuGroup(groupid);
		if (groupid) {
			ly.getSub(groupid, subid, menuid, fourid);
		} else {
			$('.left_menu').addClass('hide');
		}
	},
	/**
	 *	获得组首页图标 
	 */

	getMenuGroup: function(gid) {
		gid = gid || '001';
		var subid = '';
		var menuid = '';
		var g = '';
		$.each(groups, function(i, gt) {
			var sub = $.grep(subs, function(c) {
				subid = c.id;
				return c.parentId == gt.id;
			});
			if (sub.length > 0) {
				$.each(sub, function(k, q) {
					var a = false;
					var menu = $.grep(menus, function(me) {
						return me.parentId == q.id;
					});
					if (q.url != '' && q.url != undefined && menu.length < 1) {
						if (q.url.indexOf('?') > -1) {
							src = q.url.replace('{{interUrl}}', site.interUrl) + '&groupid=' + gt.id + '&subid=' + q.id;
						} else {
							src = q.url.replace('{{interUrl}}', site.interUrl) + '?groupid=' + gt.id + '&subid=' + q.id;
						}
					} else {
						$.each(menu, function(l, r) {
							if (l > 0) {
								return false;
							}
							if (r.url != '' && r.url != undefined) {
								if (r.url.indexOf('?') > -1) {
									src =
										r.url.replace('{{interUrl}}', site.interUrl) +
										'&groupid=' +
										gt.id +
										'&subid=' +
										q.id +
										'&menuid=' +
										r.id;
								} else {
									src =
										r.url.replace('{{interUrl}}', site.interUrl) +
										'?groupid=' +
										gt.id +
										'&subid=' +
										q.id +
										'&menuid=' +
										r.id;
								}
								a = true;
								return false;
							} else {
								src = site.interUrl + '404.html';
							}
						});
					}
					if (a) {
						return false;
					}
				});
			} else {
				if (gt.url) {
					src = gt.url.replace('{{interUrl}}', site.interUrl) + '?groupid=' + gt.id;
				} else {
					src = site.interUrl + '404.html';
				}
			}
			if (gt.id == gid) {
				if (subid) {
					g +=
						'<a href="' +
						src +
						'" point="' +
						gt.name +
						'" class="active"><i class="iconfont ' +
						gt.icon +
						'"></i><span>' +
						gt.name +
						'</span></a>';
				} else {
					g +=
						'<a href="' +
						src +
						'" point="' +
						gt.name +
						'" class="active"><i class="iconfont ' +
						gt.icon +
						'"></i><span>' +
						gt.name +
						'</span></a>';
				}
			} else {
				if (subid) {
					g +=
						'<a href="' +
						src +
						'" point="' +
						gt.name +
						'"><i class="iconfont ' +
						gt.icon +
						'"></i><span>' +
						gt.name +
						'</span></a>';
				} else {
					g +=
						'<a href="' +
						src +
						'" point="' +
						gt.name +
						'"><i class="iconfont ' +
						gt.icon +
						'"></i><span>' +
						gt.name +
						'</span></a>';
				}
			}
		});
		$('.menu_groups').html(g);
		if (window.localStorage.getItem('groupEq') != '' && window.localStorage.getItem('groupEq') != null) {
			$('.menu_groups')
				.find('a')
				.eq(window.localStorage.getItem('groupEq'))
				.addClass('active')
				.siblings('a')
				.removeClass('active');
		}
		$('.menu_groups a').hover(
			function() {
				if (window.localStorage.getItem('aside_mark') == 'open') {
					var points = $(this).attr('point');
					var scrollTop = $('.menu_groups')[0].scrollTop;
					var ofLeft = $(this)[0].offsetWidth;
					var ofTop = $(this)[0].offsetTop + 59 - scrollTop + 'px';
					$('body').append(
						'<div id="pointTips" class="point_tips" style="left:48px;top:' +
							ofTop +
							'">' +
							points +
							'</div>'
					);
				}
			},
			function() {
				$('#pointTips').remove();
			}
		);
		$('.menu_groups').niceScroll({
			cursorcolor: 'rgba(255,255,255,.1)',
			cursorwidth: '5px',
			cursorborderradius: 0,
			cursorborder: 0
		});
	},
	/**
	 *	获得左侧菜单 
	 */
	getSub: function(groupid, subid, menuid, fourid) {
		var m = '',
			src = '',
			s = '',
			hdsub = false,
			show = '',
			hdmenu = false;
		if (groupid != '') {
			var sub = $.grep(subs, function(ic) {
				return ic.parentId == groupid;
			});
			if (sub.length == 1) {
				hdsub = true;
			} else if (sub.length == 0) {
				hdsub = true;
				hdmenu = true;
			}

			$.each(sub, function(i, q) {
				src = '';
				if (q.id == subid) {
					s = 'active';
					if (menuid == '') {
						s = 'active subActive';
					}
				} else {
					s = '';
				}
				var menu = $.grep(menus, function(me) {
					return me.parentId == q.id;
				});
				if (menu.length == 1) {
					hdmenu = true;
				}
				if (q.url != '' && q.url != undefined) {
					if (q.url.indexOf('?') > -1) {
						src = q.url.replace('{{interUrl}}', site.interUrl) + '&groupid=' + groupid + '&subid=' + q.id;
					} else {
						src = q.url.replace('{{interUrl}}', site.interUrl) + '?groupid=' + groupid + '&subid=' + q.id;
					}
				} else {
					$.each(menu, function(l, r) {
						if (r.url != '' && r.url != undefined) {
							if (r.url.indexOf('?') > -1) {
								src =
									r.url.replace('{{interUrl}}', site.interUrl) +
									'&groupid=' +
									groupid +
									'&subid=' +
									q.id +
									'&menuid=' +
									r.id;
							} else {
								src =
									r.url.replace('{{interUrl}}', site.interUrl) +
									'?groupid=' +
									groupid +
									'&subid=' +
									q.id +
									'&menuid=' +
									r.id;
							}
							return false;
						}
					});
				}
				if (menu.length > 0) {
					var four = $.grep(fours, function(fr) {
						return fr.parentId == menu[0].id;
					});
					if (four.length) {
						if (four[0].url.indexOf('?') > -1) {
							src =
								four[0].url.replace('{{interUrl}}', site.interUrl) +
								'&groupid=' +
								groupid +
								'&subid=' +
								q.id +
								'&menuid=' +
								menu[0].id +
								'&fourid=' +
								four[0].id;
						} else {
							src =
								four[0].url.replace('{{interUrl}}', site.interUrl) +
								'?groupid=' +
								groupid +
								'&subid=' +
								q.id +
								'&menuid=' +
								menu[0].id +
								'&fourid=' +
								four[0].id;
						}
					}
					m +=
						'<div class="' +
						s +
						'"><dt class="two ' +
						s +
						'"><a href="' +
						src +
						'" ><span>' +
						q.name +
						'</span></a></dt><dd class="three">';
				} else {
					m +=
						'<div class="' +
						s +
						'"><dt class="two ' +
						s +
						' noNext"><a href="' +
						src +
						'" >' +
						q.name +
						'</a></dt><dd class="three">';
				}
				var isFour = false;
				$.each(menu, function(j, me) {
					var four = $.grep(fours, function(fr) {
						return fr.parentId == me.id;
					});
					if (me.url.indexOf('?') > -1) {
						src =
							me.url.replace('{{interUrl}}', site.interUrl) +
							'&groupid=' +
							groupid +
							'&subid=' +
							q.id +
							'&menuid=' +
							me.id;
					} else if (me.url != '') {
						src =
							me.url.replace('{{interUrl}}', site.interUrl) +
							'?groupid=' +
							groupid +
							'&subid=' +
							q.id +
							'&menuid=' +
							me.id;
					} else {
						src = site.interUrl + '404.html';
					}
					if (me.id == menuid) {
						s = 'active';
						if (menuid != '') {
							s = 'active subActive';
						}
						if (fourid != '') {
							s = 'active';
						}
					} else {
						s = '';
					}
					if (four.length > 0) {
						isFour = true;
						if (src.indexOf('404') > -1) {
							fUrl = four[0].url;
							if (fUrl.indexOf('?') > -1) {
								src =
									fUrl.replace('{{interUrl}}', site.interUrl) +
									'&groupid=' +
									groupid +
									'&subid=' +
									q.id +
									'&menuid=' +
									me.id +
									'&fourid=' +
									four[0].id;
							} else if (fUrl != '') {
								src =
									fUrl.replace('{{interUrl}}', site.interUrl) +
									'?groupid=' +
									groupid +
									'&subid=' +
									q.id +
									'&menuid=' +
									me.id +
									'&fourid=' +
									four[0].id;
							} else {
								src = site.interUrl + '404.html';
							}
						}
						m +=
							'<dt class="three ' +
							s +
							'"><a href="' +
							src +
							'" class=""><span>' +
							me.name +
							'</span></a></dt><dd class="four">';
						$.each(four, function(r, f) {
							if (f.url.indexOf('?') > -1) {
								src =
									f.url.replace('{{interUrl}}', site.interUrl) +
									'&groupid=' +
									groupid +
									'&subid=' +
									q.id +
									'&menuid=' +
									me.id +
									'&fourid=' +
									f.id;
							} else if (f.url != '') {
								src =
									f.url.replace('{{interUrl}}', site.interUrl) +
									'?groupid=' +
									groupid +
									'&subid=' +
									q.id +
									'&menuid=' +
									me.id +
									'&fourid=' +
									f.id;
							} else {
								src = site.interUrl + '404.html';
							}
							if (f.id == fourid) {
								as = 'active';
							} else {
								as = '';
							}
							m += '<a href="' + src + '" class="' + as + '" >' + f.name + '</a>';
						});
						m += '</dd>';
					} else {
						if (isFour) {
							m +=
								'<dd class="three ' +
								s +
								'"><a href="' +
								src +
								'" class="' +
								s +
								'" >' +
								me.name +
								'</a></dd>';
						} else {
							m += '<a href="' + src + '" class="' + s + '" >' + me.name + '</a>';
						}
					}
				});
				m += '</dd></div>';
			});
			$('.left_menu .sub').html(m);
		} else {
			$('.left_menu .sub').html('目录参数有误');
		}
		if (!m) {
			$('.left_menu').addClass('hide');
			$('.btnBox').css('left', '198px');
		}

		$('.left_menu').niceScroll({
			cursorcolor: '#3B86FF',
			cursorwidth: '5px',
			cursorborderradius: 0,
			cursorborder: 0
		});
	},

	/**
	 *	弹出轻量提示 toast
	 */
	toast: function(text, url, speed) {
		var speed = speed||5000;
		if (url) {
			window.sessionStorage.setItem('toast_text_access', text);
			if (url == 'reload') {
				window.location.reload();
			} else if (url == 'ignore') {
			} else {
				ly.goto(url);
			}
			return false;
		}
		if ($('.toastBox').length < 1) {
			$('body').append('<div class="toastBox"></div>');
		}
		if ($('.toasts').length < 1) {
			$('.toastBox').attr('d-toast', 0);
		} else {
			$('.toastBox').attr('d-toast', $('.toastBox').attr('d-toast') - -1);
		}
		var j = $('.toastBox').attr('d-toast');
		var t = (j % 10) * 55;
		var i = 't' + j;
		var h = '<div class="toasts" style="top:' + t + 'px" id=' + i + '><span class="toast">' + text + '</span><div>';
		if ($('body').find('.toasts').length < 1) {
			$('.toastBox').append(h);
		}
		$('#' + i).animate(
			{
				height: 'auto'
			},
			speed,
			function() {
				$(this).animate(
					{
						opacity: 0,
						'margin-top': -30
					},
					500,
					function() {
						$(this).remove();
					}
				);
			}
		);
	},
	/**
	 *	弹出提示 alert
	 */
	alert: function(m, c) {
		var h =
			'<div class="cover" id="syalert"><div class="ctr">            <div class="window"><div class="con">' +
			m +
			'</div><div class="btns"><button class="btn ok red">确定</button></div></div></div></div>';
		$('body').append(h);
		var w = $('body #syalert');
		w.find('.ok').focus();
		w.find('.con').html(m);
		$(window).keydown(function(e) {
			if (e.which == 27) {
				w.find('.ok').click();
			}
		});
		w.on('click', '.ok', function() {
			if (typeof c == 'function') {
				c();
			}
			$(this).parents('#syalert').fadeOut(200, function() {
				$(this).remove();
			});
		});
	},
	/**
	 *	弹出确认框 confirm
	 */
	confirm: function(m, c, b, t) {
		t = t || '确定,取消';
		var ot = t.split(',');
		var h =
			'<div class="cover" id="syalert"><div class="ctr"><div class="window"><div class="con">' +
			m +
			'</div><div class="btns"><button class="btn ok red">' +
			ot[0] +
			'</button></div></div></div></div>';
		$('body').append(h);

		var w = $('body #syalert');
		w.find('.ok').focus();
		w.find('.con').html(m);
		w.find('.btns').append(" <button class='btn cancel'>" + ot[1] + '</button>');
		$(window).keydown(function(e) {
			if (e.which == 27) {
				w.find('.cancel').click();
			}
		});
		w.on('click', '.ok', function() {
			if (typeof c == 'function') {
				c();
			}
			$(this).parents('#syalert').fadeOut(200, function() {
				$(this).remove();
			});
		});
		w.on('click', '.cancel', function() {
			if (typeof b == 'function') {
				b();
			}
			$(this).parents('#syalert').fadeOut(200, function() {
				$(this).remove();
			});
		});
	},
	/**
	 *	跳转到页面 url：路径，b：新窗口
	 */
	goto: function(url, b) {
		var u = url.match(/\{\{(.+?)\}\}/g);
		if (u != '' && u != undefined) {
			var um = u.toString();
			var up = um.substring(2, um.length - 2);
			var uu = site[up];
			url = url.replace(um, uu);
		}
		var obj = ly.parseQueryString(url);
		window.localStorage.setItem('group', ly.getUrlParam('groupid') || 1);
		window.localStorage.setItem('sub', ly.getUrlParam('subid') || 0);
		window.localStorage.setItem('menu', ly.getUrlParam('menuid') || 0);
		window.localStorage.setItem('four', ly.getUrlParam('fourid') || 0);
		var g = obj.groupid || window.localStorage.getItem('group');
		var s = obj.subid || window.localStorage.getItem('sub');
		var m = obj.menuid || window.localStorage.getItem('menu');
		var f = obj.fourid || window.localStorage.getItem('four');
		var r = 'groupid=' + g + '&subid=' + s + '&menuid=' + m + '&fourid=' + f;
		url = ly.delQueStr(url, 'groupid');
		url = ly.delQueStr(url, 'subid');
		url = ly.delQueStr(url, 'menuid');
		url = ly.delQueStr(url, 'fourid');
		if (b) {
			window.open(url);
		} else if (url.indexOf('login.html') > -1) {
			window.location.href = url;
		} else {
			if (url.match('[?]')) {
				url = url + '&' + r;
			} else {
				url = url + '?' + r;
			}
			window.location.href = url;
		}
	},

	/**
	 *	获取路径所有参数
	 */
	parseQueryString: function(url) {
		var str = url.split('?')[1] || '';
		var iterms = str.split('&');
		var arr,
			json = {};
		for (var i = 0; i < iterms.length; i++) {
			arr = iterms[i].split('=');
			json[arr[0]] = arr[1];
		}
		return json;
	},
	/**
	 * 删除参数值
	 */
	delQueStr: function(url, ref) {
		var str = '';

		if (url.indexOf('?') != -1) str = url.substr(url.indexOf('?') + 1);
		else return url;
		var arr = '';
		var returnurl = '';
		var setparam = '';
		if (str.indexOf('&') != -1) {
			arr = str.split('&');
			for (i in arr) {
				if (arr[i].split('=')[0] != ref) {
					returnurl = returnurl + arr[i].split('=')[0] + '=' + arr[i].split('=')[1] + '&';
				}
			}
			return url.substr(0, url.indexOf('?')) + '?' + returnurl.substr(0, returnurl.length - 1);
		} else {
			arr = str.split('=');
			if (arr[0] == ref) return url.substr(0, url.indexOf('?'));
			else return url;
		}
	}
};

/**
 *	显示加载
 */
$.fn.showloading = function(options) {
	var obj,
		defaults = {
			lid: 'sy_loading',
			parent: false,
			timeout: 0,
			bgcolor: ''
		};
	var opts = $.extend({}, defaults, options);
	if (opts.parent) {
		obj = $('body');
	} else {
		obj = $(this) || $('body');
	}
	if (obj.css('position') != 'absolute' && !obj.css('position') != 'fixed') {
		obj.css('position', 'relative');
	}
	var h =
		'<div class="loading" style="background-color:' +
		opts.bgcolor +
		';" lid="' +
		opts.lid +
		'"><div class="loader-inner ball-spin-fade-loader"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>';
	var t = ''; //'<div class="texter">' + ly.helpText() + '</div>';
	if (obj.selector == 'body' || obj.selector == '.box') {
		h += t;
	} else {
		obj.find('.loader-inner').css('margin-top', 0);
	}
	if (obj.has('.loading').length > 0) {
		obj.find('.loading').remove();
	}
	obj.append(h + '</div>');
	if (opts.timeout) {
		setTimeout(function() {
			$('[lid=' + opts.lid + ']').remove();
			if (obj.css('position') == 'relative') {
				obj.css('position', 'static');
			}
		}, opts.timeout);
	}
};
/**
 *	关闭加载
 */
$.fn.hideloading = function(options) {
	if (loadTime == compTime) {
		var obj,
			defaults = {
				lid: 'sy_loading',
				parent: false
			};
		var opts = $.extend({}, defaults, options);
		if (opts.parent) {
			obj = window.parent.$('body');
		} else {
			obj = $(this) || $('body');
		}
		obj.find('[lid=' + opts.lid + ']').fadeOut(500, function() {
			obj.find('[lid=' + opts.lid + ']').remove();
			$('.whiteboard').remove();
			if (obj.css('position') == 'relative') {
				obj.css('position', 'static');
			}
		});
	}
};

/**
 *	显示贴士（tips）
 *	创建时间：2017-08-12
 *	作者：fan.jin
 */
$.fn.showTips = function(options) {
	var h = '',
		defaults = {
			text: '这是一个提示',
			type: '', //waring,error,success
			timeout: 0
		};
	var opts = $.extend({}, defaults, options);
	var i = 't' + parseInt(Math.random() * 10000);
	h += '<div class="tips ' + opts.type + '" id="' + i + '">';
	if (opts.timeout) {
		h += '<div class="timer"></div>';
	} else {
		h += '<div class="cls"><div class="iconfont icon-close"></div></div>';
	}
	h += '<div class="con">' + opts.text + '</div></div>';
	$(this).append(h);
	var wh = $('#' + i).height() + 20;
	$('#' + i).height(0);
	$('#' + i).animate(
		{
			height: wh
		},
		300,
		function() {
			$(this).height('auto');
		}
	);

	$('#' + i).on('click', '.cls', function() {
		$(this).parents('.tips').animate({
			height: 0,
			padding: '0 20px'
		}, 300, function() {
			$(this).remove();
		});
	});
	if (opts.timeout) {
		$('#' + i).find('.timer').animate({
			width: 0
		}, opts.timeout, function() {
			$(this).parents('.tips').animate({
				height: 0,
				padding: '0 20px'
			}, 300, function() {
				$(this).remove();
			});
		});
	}
};
$('body').showloading({ lid: 'bodyloading' });
(function($) {
	var toastTxt = window.sessionStorage.getItem('toast_text_access');
	if (toastTxt) {
		ly.toast(toastTxt);
		window.sessionStorage.removeItem('toast_text_access');
	}
	$('body').hideloading({ lid: 'bodyloading' });
	/**
	 *	选项卡插件
	 */
	$.fn.fTabs = function(options) {
		var defaults = {
			switchingMode: 'click',
			showItem: 0,
			tabObj: '.tabs li',
			activeClass: 'active',
			boxObj: '.box',
			usePt: false,
			success: '',
			beforeChange: '',
			afterChange: ''
		};
		var opts = $.extend({}, defaults, options);
		var obj = $(this);
		if (opts.usePt) {
			obj.find(opts.tabObj + '[pt=' + opts.showItem + ']').addClass(opts.activeClass);
			obj.find(opts.boxObj).hide();
			obj.find(opts.boxObj + '[pt=' + opts.showItem + ']').fadeIn(100);
		} else {
			obj.find(opts.tabObj).eq(opts.showItem).addClass(opts.activeClass);
			obj.find(opts.boxObj).hide().eq(opts.showItem).fadeIn(100);
		}
		var total = obj.find(opts.tabObj).length;
		if (typeof opts.success == 'function') {
			var index = opts.showItem;
			opts.success(index, total);
		}
		obj.find(opts.tabObj).on(opts.switchingMode, function() {
			var prev = obj.find(opts.tabObj + '.active').index();
			var index = $(this).index();
			if (typeof opts.beforeChange == 'function') {
				opts.beforeChange(index, prev, total);
			}
			obj.find(opts.tabObj).removeClass(opts.activeClass);
			$(this).addClass(opts.activeClass);
			obj.find(opts.boxObj).hide();
			if (opts.usePt) {
				var j = $(this).attr('pt');
				obj.find(opts.boxObj + '[pt=' + j + ']').fadeIn(100);
			} else {
				obj.find(opts.boxObj).eq($(this).index()).fadeIn(100);
			}

			if (typeof opts.afterChange == 'function') {
				opts.afterChange(index, prev, total);
			}
		});
	};

	/**
	 *	图片剪裁上传
	 */
	$.fn.imgUploader = function(options) {
		var _this = $(this),
			defaults = {
				size: '320,180', //默认尺寸
				prebox: $(this).attr('class')
			};
		var opts = $.extend({}, defaults, options),
			wh = opts.size.split(','),
			wa,
			ha,
			b = opts.prebox;
		if (wh[0] >= 500) {
			wa = parseInt(wh[0]) * 2 + parseInt(20) + 40;
			ha = parseInt(wh[1]) * 1 + parseInt(74) + 40;
		} else if (wh[0] <= 50) {
			wa = parseInt(wh[0]) * 3.5 + parseInt(20) + 40;
			ha = parseInt(wh[1]) * 8 + parseInt(74) + 40;
		} else {
			wa = parseInt(wh[0]) * 2.5 + parseInt(20) + 40;
			ha = parseInt(wh[1]) * 1.5 + parseInt(74) + 40;
		}
		_this.after(
			'<div class="cover"><div class="ctr"><div class="imguploader" style="width:' +
				wa +
				'px; height:' +
				ha +
				'px"><div class="t">编辑并上传图片<div class="cls"><div class="iconfont icon-close"></div></div></div><div class="c"></div></div></div></div>'
		);
		var obj = _this.next('.cover');
		obj
			.find('.c')
			.html(
				'<iframe style="height:' +
					(ha - 34) +
					'px" src="' +
					site.interUrl +
					'/js/imguploader/index.html?w=' +
					wh[0] +
					'&h=' +
					wh[1] +
					'&b=' +
					b +
					'" frameborder="0"></iframe>'
			);
		obj.hide();
		_this.find('span.up').click(function() {
			obj.show();
			$('.right_con').css('overflow', 'hidden');
		});
		obj.find('.cls').click(function() {
			close();
			return false;
		});
		var close = function() {
			obj.hide();
			$('.right_con').css('overflow', 'auto');
		};
	};
	/**
	 *	上传组件
	 */

	$.fn.videoUploader = function() {
		var _this = $(this);
		if (_this.siblings('.videobox').length > 0) {
			return false;
		}
		_this.hide();
		pid = Uniquestring('viodeprv');
		_this.attr('prvbox', pid);
		_this.before(
			'<div class="videobox"><span class="up"></span><span class="del"></span><span class="progress"><i></i><span></span></span><span class="process"><i></i></span><video></video></div>'
		);
		if ($(this).attr('disabled') != undefined) {
			_this.prev('.videobox').html('').css('cursor', 'no-drop');
		}
		_this.after(
			'<div class="cover"><div class="ctr"><div class="imguploader video"><div class="t">视频上传<div class="cls"><div class="iconfont icon-close"></div></div></div><div class="c"></div></div></div></div>'
		);
		var obj = _this.next('.cover');
		obj.hide();
		_this.find('span.up').click(function() {
			obj.show();
			$('.right_con').css('overflow', 'hidden');
		});
		obj.find('.cls').click(function() {
			close();
			return false;
		});
		var close = function() {
			obj.hide();
			$('.right_con').css('overflow', 'auto');
			obj.find('iframe').contents().find('#videoPlay').attr('src', '');
			// if (_this.prev(".videobox").hasClass("active")) {
			// 	obj.find("iframe").attr("src", obj.find("iframe").attr("src"));
			// }
		};
		var v = _this.attr('aliid') || '';
		if (v != '') {
			_this.prev('.videobox').addClass('active');
			var bg = _this.attr('cover');
			_this.removeAttr('cover');
			if (bg != '' && bg != undefined) {
				_this.prev('.videobox').css('background-image', 'url(' + bg + ')');
			}
		}
		_this.prev('.videobox').children('.up').click(function() {
			_this.next('.cover').show();
			v = _this.attr('aliid') || '';
			var b = _this.attr('prvbox');
			obj
				.find('.c')
				.html(
					'<iframe style="height:480px" src="' +
						site.interUrl +
						'/js/videouploader/videouploader.html?v=' +
						v +
						'&b=' +
						b +
						'" frameborder="0"></iframe>'
				);
		});
		_this.prev('.videobox').children('.progress').click(function() {
			_this.next('.cover').show();
		});
		_this.prev('.videobox').children('.del').click(function() {
			deleteVideo();
		});
		var deleteVideo = function() {
			_this.val('');
			_this.removeAttr('fileurl');
			_this.removeAttr('fileType');
			_this.removeAttr('fileSize');
			_this.removeAttr('fileName');
			_this.prev('.videobox').find('video').removeAttr('src');
			_this.prev('.videobox').removeClass('active');
			_this.prev('.videobox').removeAttr('style');
		};
	};
})(jQuery);
/**
 *	删格化布局间距——封装方法
 */
function addGutter() {
	$('[gutter]').each(function() {
		var m = $(this).attr('gutter') || 0;
		var w = $(this).width();
		$(this).children().css({
			'padding-left': m / 2,
			'padding-right': m / 2
		});
		$(this).css({
			'margin-left': -m / 2,
			'margin-right': -m / 2
		});
		$(this).children().children('span.address,span.date,span.unit').css({
			right: m / 2
		});
	});
}

/**
 *	显示提示文字
 */
var setPoint = function() {
	$('[point]').each(function() {
		var c;
		if ($(window).width() - $(this).offset().left - $(this).width() < 300) {
			c = 'left';
		} else {
			c = '';
		}
		$(this).find('.point').remove();
		$(this).append('<div class="point ' + c + '">' + $(this).attr('point') + '</div>');
		var h = $(this).find('.point').height();
		$(this).find('.point').attr('h', h); //.hide();
		if ($(window).height() - $(this).offset().top < h) {
			$(this)
				.find('.point')
				.css({
					top: 'auto',
					bottom: '0'
				})
				.addClass('bottom');
		}
		$(this).hover(
			function() {
				$(this).css('position', 'relative');
				$(this).children('.point').show();
			},
			function() {
				$(this).css('position', 'static');
				$(this).children('.point').hide();
			}
		);
	});
};
setPoint();
/**
 *	按钮列表
 */
function setBtn() {
	$('.btnlist').each(function() {
		var obj = $(this);
		var cl = obj.find('.btnbox').children().length;
		if (obj.find('.btnbox').length > 0) {
			for (var i = 0; i < cl; i++) {
				// console.log(obj.find(".btnbox").children().eq(0));
				obj.append(obj.find('.btnbox').children().eq(0).remove());
			}
			obj.find('.btnbox').remove();
			obj.find('.slt').remove();
		}
		var l = obj.children().length;
		var h = (l - 1) * 34;
		var r = window.location.search.substr(1);
		var u;
		obj.find('a').each(function() {
			if ($(this).attr('href').indexOf('.html') > 0) {
				u = $(this).attr('href');
				if (u.match('[?]')) {
					$(this).attr('href', u + '&' + r);
				} else {
					$(this).attr('href', u + '?' + r);
				}
			}
		});
		if (l > 1) {
			obj.append('<div class="btnbox"></div>');
			obj.append('<div class="slt"></div>');
			for (var i = 1; i < l; i++) {
				obj.children('.btnbox').append(obj.children().eq(1).remove());
			}
			obj.find('.slt').click(function() {
				if (!$(this).hasClass('clt')) {
					obj.find('.btnbox').animate({
						height: h
					}, 200, function() {
						obj.find('.slt').addClass('clt');
					});
				} else {
					obj.find('.btnbox').animate({
						height: 1
					}, 200, function() {
						obj.find('.slt').removeClass('clt');
					});
				}
			});
			$('body').click(function() {
				if (obj.find('.slt').hasClass('clt')) {
					obj.find('.btnbox').animate({
						height: 1
					}, 200, function() {
						obj.find('.slt').removeClass('clt');
					});
				}
			});
		} else {
			obj.children().css('padding-right', 0);
		}
	});
}
setBtn();

var setVideoUploader = function() {
	$('input[type=upvideo]').each(function() {
		$(this).videoUploader({});
	});
};
/**
 *	复选框
 */
$('label.chk').each(function() {
	var obj = $(this);
	if (obj.find('b').length == 0) {
		obj.find('[type=checkbox]').after('<b></b>');
	}
});
/**
 *	单选框
 */
$('label.rad').each(function() {
	var obj = $(this);
	if (obj.find('b').length == 0) {
		obj.find('[type=radio]').after('<b></b>');
	}
});
/**
 *	防止表单按回车提交,并只触发主按钮
 */
$('form').prepend("<input type='text' style='display:none'></input>");
$('.btn').each(function() {
	if (typeof $(this).attr('type') == 'undefined') {
		$(this).attr('type', 'button');
	}
});
$('form').keydown(function(e) {
	if (e.which == 13) {
		$('form').find('.btn[main]').click();
		return false;
	}
});
/**
 *	列表选择
 */
$('.datalist').on('click', 'td:not(:has(label))', function() {
	var _this = $(this);
	_this.parents('tr').find('input[type=checkbox]').click();
	var chk = _this.parents('tr').find('input[type=checkbox]');
	var n = chk.attr('name');
	var c = $("input[name='" + n + "']:checked").length;
	var a = $("input[name='" + n + "']").length;
	if (c == a) {
		$("input[data-for='" + n + "']").prop('checked', true);
	} else {
		$("input[data-for='" + n + "']").prop('checked', false);
	}
});
/**
 *	列表全选
 */
$('.chk.all input').on('click', function() {
	var n = $(this).attr('data-for');
	if ($(this).is(':checked')) {
		$(this).parents('.datalist').find('table').find("input[name='" + n + "']").prop('checked', true);
		//判断禁用
		var _disabled = $(this).parents('.datalist').find('table').find("input[name='" + n + "']");
		$(_disabled).each(function() {
			if ($(this).prop('disabled') == true) {
				$(this).prop('checked', false);
			}
		});
	} else {
		$(this).parents('.datalist').find('table').find("input[name='" + n + "']").prop('checked', false);
	}
});

/**
 *	显示/隐藏容器
 */
$('[toggle]').each(function() {
	var o = $($(this).attr('toggle'));
	var w = $(this).attr('toggletext').split(',');
	var p = $(this).attr('open');
	o.attr('data-height', o.outerHeight());
	if ($(this).attr('open') != 'open') {
		o.css({
			height: 0,
			'padding-top': 0,
			'padding-bottom': 0,
			overflow: 'hidden'
		});
	} else {
		$(this).html(w[1]);
	}
	$(this).click(function() {
		if (o.height() == 0) {
			$(this).html(w[1]);
			$('.right_con').animate(
				{
					scrollTop: $(this).offset().top - 150
				},
				300
			);
			o.animate(
				{
					height: o.attr('data-height')
				},
				300,
				function() {
					$(this)
						.css({
							height: 'auto',
							overflow: 'visible'
						})
						.removeAttr('style');
				}
			);
		} else {
			$(this).html(w[0]);
			o.animate(
				{
					height: 0,
					'padding-top': 0,
					'padding-bottom': 0
				},
				300,
				function() {
					$(this).css({
						overflow: 'hidden'
					});
				}
			);
		}
	});
});

/**
 *	日期控件触发验证
 */
var tovalid = function(e) {
	e.elem.blur();
};
$.fn.tovalid = function(e, o) {
	setTimeout(function() {
		$(this.elem).blur();
	}, 50);
};
/**
 *	日期控件
 */
$.fn.createDateor = function(options) {
	var defaults = {
		type: 'date',
		range: false,
		maxDate: null,
		minDate: null,
		isToday: false
	};
	var _this = $(this);
	var opts = $.extend({}, defaults, options);
	var oldDate = '';
	var fmt;
	switch (opts.type) {
		case 'date':
			fmt = 'yyyy-MM-dd';
			break;
		case 'datetime':
			fmt = 'yyyy-MM-dd HH:mm:ss';
			break;
		case 'time':
			fmt = 'HH:mm:ss';
			break;
		case 'month':
			fmt = 'yyyy-MM';
			break;
		case 'year':
			fmt = 'yyyy';
			break;
		default:
			fmt = 'yyyy-MM-dd';
			break;
	}
	var icon = opts.type == 'time' ? 'time' : 'date';
	if ($('#laydatejs').length < 1) {
		$('#config_js').after('<script id="laydatejs" src="' + site.interUrl + 'js/laydate/laydate.js"></script>');
	}
	_this.prop('readonly', true);
	_this.prop('type', 'text');
	if (_this.parent().css('position') != 'absolute' && !_this.parents().css('position') != 'fixed') {
		_this.parent().css({
			position: 'relative',
			'font-size': '0'
		});
	}
	_this.after('<span class="' + icon + '"></span>');
	dv = _this.attr('isinitVal') == undefined ? false : true;
	if (opts.type == 'time' && !opts.rang) {
		laydate.render({
			elem: _this.get(0),
			type: 'time',
			trigger: 'click',
			theme: 'molv',
			format: fmt,
			ready: function(date) {
				oldDate = _this.val().replace(/-/g, '');
			},
			done: function(i, d) {
				var currDate = i.replace(/-/g, '');
				if (i != oldDate) {
					boolean = true;
				}
				setTimeout(function() {
					$(_this).blur();
				}, 50);
			}
		});
	} else if (opts.range) {
		var start = laydate.render({
			elem: _this.get(0),
			theme: 'molv',
			format: fmt,
			btns: [ 'clear', 'confirm' ],
			type: opts.type,
			trigger: 'click',
			max: dateConversion(opts.maxDate, 'max'),
			min: dateConversion(opts.minDate, 'min'),
			ready: function(date) {
				oldDate = _this.val().replace(/-/g, '');
			},
			done: function(val, dates) {
				var currDate = val.replace(/-/g, '');
				if (val != oldDate) {
					boolean = true;
				}
				var dmin = this.min;
				if (val != '') {
					$.each(end, function(i, m) {
						m.config.min = {
							year: dates.year,
							month: dates.month - 1, //关键
							date: dates.date,
							hours: dates.hours,
							minutes: dates.minutes,
							seconds: dates.seconds
						};
					});
				} else {
					$.each(end, function(i, m) {
						m.config.min = dmin;
					});
				}
				setTimeout(function() {
					$(_this).blur();
				}, 50);
			}
		});
		var ed = _this.attr('relation');
		ed = ed.split(',');
		var end = [];
		$.each(ed, function(i, m) {
			end[i] = laydate.render({
				elem: $(m).get(0),
				theme: 'molv',
				format: fmt,
				trigger: 'click',
				btns: [ 'clear', 'confirm' ],
				type: opts.type,
				max: dateConversion(opts.maxDate, 'max'),
				min: dateConversion(opts.minDate, 'min'),
				ready: function(date) {
					oldDate = _this.val().replace(/-/g, '');
				},
				done: function(val, dates) {
					var currDate = val.replace(/-/g, '');
					if (val != oldDate) {
						boolean = true;
					}
					var dmax = this.max;
					if (val != '') {
						start.config.max = {
							year: dates.year,
							month: dates.month - 1,
							date: dates.date,
							hours: dates.hours,
							minutes: dates.minutes,
							seconds: dates.seconds
						};
					} else {
						start.config.max = dmax;
					}
					setTimeout(function() {
						$(m).blur();
					}, 50);
				}
			});
		});
	} else if (_this.attr('trigger') != undefined) {
		return false;
	} else {
		laydate.render({
			elem: _this.get(0),
			theme: 'molv',
			format: fmt,
			trigger: 'click',
			btns: [ 'clear', 'confirm' ],
			type: opts.type,
			max: dateConversion(opts.maxDate, 'max'),
			min: dateConversion(opts.minDate, 'min'),
			ready: function(date) {
				oldDate = _this.val().replace(/-/g, '');
			},
			done: function(i, d) {
				var currDate = i.replace(/-/g, '');
				if (i != oldDate) {
					boolean = true;
				}
				setTimeout(function() {
					$(_this).blur();
					$(_this).change();
				}, 50);
			}
		});
	}
};
var setDateinput = function() {
	//日期至日期
	$('input[type=datetime],input[type=date],input[type=year],input[type=month],input[type=time]').each(function() {
		var _this = $(this);
		var max = _this.attr('maxdate') || null;
		var min = _this.attr('mindate') || null;
		var range = _this.attr('relation') == undefined || _this.attr('relation') == '' ? false : true;
		_this.createDateor({
			type: _this.attr('type'),
			range: range,
			maxDate: max,
			minDate: min,
			isToday: false
		});
	});
};
setDateinput();

function dateConversion(dt, type) {
	var ndt;
	if (dt == 'today') {
		var now = new Date();
		ndt = type == 'max' ? dateFormat(now, 'yyyy-MM-dd HH:mm:ss') : dateFormat(now, 'yyyy-MM-dd HH:mm:ss');
	} else if (dt == 'thisyear') {
		var now = new Date();
		var firstDate = new Date(now.getFullYear(), 0, 1);
		var lastDate = new Date(now.getFullYear(), 11, 31);
		ndt =
			type == 'max' ? dateFormat(lastDate, 'yyyy-MM-dd 23:59:59') : dateFormat(firstDate, 'yyyy-MM-dd 00:00:00');
	} else if (dt == 'thismonth') {
		var now = new Date();
		var firstDate = new Date(now.getFullYear(), now.getMonth(), 1);
		var currentMonth = now.getMonth();
		var nextMonth = currentMonth + 1;
		var nextMonthFirstDay = new Date(now.getFullYear(), nextMonth, 1);
		var oneDay = 1000 * 60 * 60 * 24;
		var lastDate = new Date(nextMonthFirstDay - oneDay);
		ndt =
			type == 'max' ? dateFormat(lastDate, 'yyyy-MM-dd 23:59:59') : dateFormat(firstDate, 'yyyy-MM-dd 00:00:00');
	} else if (dt != undefined && dt.split(',')[0] == 'today') {
		var now = new Date();
		now.setDate(now.getDate() + parseInt(dt.split(',')[1]));
		ndt = type == 'max' ? dateFormat(now, 'yyyy-MM-dd HH:mm:ss') : dateFormat(now, 'yyyy-MM-dd HH:mm:ss');
	} else {
		ndt = dt;
	}
	ndt = type == 'max' ? (ndt ? ndt : '9999-12-31 23:59:59') : ndt ? ndt : '1900-01-01 00:00:00';
	return ndt;
}

/**
 *	图片上传
 */
$('[ly-type=upimg]').each(function() {
	var _this = $(this);
	var size = _this.attr('upsize');
	var preview = _this.attr('prvbox');
	var h = '<span class="up"></span><span class="del"></span>';
	if ($(this).hasClass('required')) {
		$(this).removeClass('required');
		var pd = $(this).attr('placeholder');
		var dt = $(this).attr('data-tip');
		var dv = $(this).attr('data-valid');
		var de = $(this).attr('data-error');
		h +=
			'<input type="hidden" class="required" placeholder="' +
			pd +
			'" data-tip="' +
			dt +
			'" data-valid="' +
			dv +
			'" data-error="' +
			de +
			'" >';
	} else {
		h += '<input type="hidden">';
	}
	h += '<div class="imgbox"></div>';
	_this.append(h);
	if (_this.attr('disabled') != undefined) {
		_this.css('cursor', 'no-drop');
		_this.find('.up').hide();
		_this.find('.del').hide();
	} else {
		_this.imgUploader({
			size: size,
			prebox: preview
		});
	}
});
//清空图片
$('[ly-type=upimg]').find('span.del').click(function() {
	var oldVal = $(this).parents('[ly-type=upimg]').find('input').val();
	$(this).parents('[ly-type=upimg]').removeClass('active').find('.imgbox').html('');
	$(this).parents('[ly-type=upimg]').find('input').val('');
	var newVal = $(this).parents('[ly-type=upimg]').find('input').val('');
	if (oldVal != newVal) {
		boolean = true;
	}
	ly.toast('已清空图片');
});
/**
 *	页面跳转
 */
$('body').on('click', '[goto]', function() {
	url = $(this).attr('goto');
	ly.goto(url);
});
/**
 *	下拉链接菜单插件
 *	创建时间：2017-08-02
 */

$.fn.syMenu = function(options) {
	var defaults = {
		menuName: '菜单名',
		target: '',
		list: []
	};
	var opts = $.extend({}, defaults, options);
	var obj = $(this);
	obj.append('<span>' + opts.menuName + '</span>');
	obj.addClass('sy_menu').append('<i class="iconfont icon-xiala"></i><div class="sub"></sub>');
	var m = '';
	for (var i = 0; i < opts.list.length; i++) {
		if (opts.list[i].text !== '--') {
			var src = opts.list[i].href.replace('{{interUrl}}', site.interUrl);
			if (opts.target) {
				m += '<a href="' + src + '" target="' + opts.target + '">' + opts.list[i].text + '</a>';
			} else {
				m += '<a href="' + src + '">' + opts.list[i].text + '</a>';
			}
		} else {
			m += '<span class="line"></span>';
		}
	}
	obj.find('.sub').html(m);
	obj.on('click', '.sub a', function() {
		obj.find('.sub').hide();
	});
	obj.on('mouseover', function() {
		obj.find('.sub').show();
	});
	obj.on('mouseout', function() {
		obj.find('.sub').hide();
	});
};
/**
 *	操作按钮
 */
$.fn.getOper = function() {
	$('.operation').each(function() {
		if ($(this).children('em').length < 1) {
			$(this).append('<em></em>');
		}
		var obj;
		$(this).find('em').unbind('click');
		$(this).find('em').click(function() {
			obj = $(this);
			if (!obj.hasClass('open')) {
				obj.parents('tr').siblings('tr').find('.operlist').hide();
				obj.parents('tr').siblings('tr').find('.open').removeClass('open');
				obj.prev('.operlist').show();
				obj.addClass('open');
			} else {
				obj.prev('.operlist').hide();
				obj.removeClass('open');
			}
		});
		$(this).click(function() {
			return false;
		});
		$('body').click(function() {
			$('.operlist').hide();
			$('.operation').find('em').removeClass('open');
		});
		$(this).find('.menulist').each(function() {
			var mh = $(this).height();
			var ob = $(window).height() - $(this).offset().top;
		});
		$(this).find('[goto]').click(function() {
			url = $(this).attr('goto');
			ly.goto(url);
		});
	});
};
$('.datalist').getOper();

var ajaxStatus = true;
/**
 * 方法说明：(表单请求)ajax封装
 * @param {Object} url      请求路径
 * @param {Object} loading  是否加载动画： true|false
 * @param {Object} data     请求参数：例如{"id":1}
 * @param {Object} ajaxform     请求参数 true | false
 * @param {Object} success  回调函数 或者 回调函数名
 * @param {Object} type     请求类型
 * @param {Object} cache    浏览器历史缓存
 * @param {Object} alone    独立提交（一次有效的提交）
 * @param {Object} async    异步请求  ： true | false
 * @param {Object} dataType 接收数据类型  json
 * @param {Object} error    错误处理
 */
function ajax(options) {
	var isloading = options.loading || true;
	if (isloading != 'unLoad' && $('.waiting').length == 0) {
		$('body').showloading({ lid: 'ajaxloading', lock: false });
	}
	loadTime++;
	var accessToken = window.localStorage.getItem('backstage-access-token') || '';
	var ajaxform = options.ajaxform || false;
	var type = options.type || 'post';
	var dataType = options.dataType || 'json';
	var contentType = options.contentType || 'application/json;charset=UTF-8';
	var async = options.async || true;
	var alone = options.alone || false;
	var cache = options.cache || false;
	var success = function(data) {
		if (data.code == '201') {
			ly.alert(data.msg, function() {
				var thisPage = window.location.href;
				var version = window.localStorage.getItem('backstage-version') || 'newVer';
				if (version == 'newVer') {
					window.location.href = site.interUrl + '/login.html?pageUrl=' + thisPage;
				} else {
					window.location.href = site.interUrl + '/oldLogin.html?pageUrl=' + thisPage;
				}
			});
			return false;
		}
		$('.whiteboard').remove();
		if (typeof options.callback == 'function') {
			if (data.refreshToken != undefined) {
			}
			options.callback(data);
		}
	};
	var error =
		error ||
		function(data) {
			$('.btnBox').find('.btn').prop('disabled', false);
			if (data.status == 404) {
				ly.toast('[' + data.status + ']服务器繁忙');
			} else if (data.status == 503) {
				ly.toast('[' + data.status + ']服务器繁忙');
			} else if (data.status == 0) {
				ly.toast('[' + data.status + ']服务器繁忙');
			} else {
				ly.toast('[' + data.status + ']服务器繁忙');
			}
			ajaxStatus = true;
		};
	/*判断是否可以发送请求*/
	if (!ajaxStatus) {
		return false;
	}
	ajaxStatus = false; //禁用ajax请求
	/*正常情况下1秒后可以再次多个异步请求，为true时只可以有一次有效请求（例如添加数据）*/
	if (!alone) {
		ajaxStatus = true;
	}
	var reqObj = {
		headers: {
			'access-token': accessToken
		},
		complete: function() {
			compTime++;
			if (loadTime == compTime) {
				if ($('.waiting').length > 0) {
					$('.waiting').fadeOut(200);
					$('.waiting').remove();
				}
				if ($('.loading').length > 0) {
					$('body').hideloading({
						lid: 'ajaxloading'
					});
				}
			}
		},
		url: options.url,
		data: JSON.stringify(options.data),
		type: type,
		dataType: dataType,
		contentType: contentType,
		async: async,
		success: success,
		error: error,
		jsonpCallback: 'jsonp' + new Date().valueOf().toString().substr(-4),
		beforeSend: function() {}
	};
	if (ajaxform) {
		reqObj.data = options.data;
		reqObj.contentType = 'application/x-www-form-urlencoded; charset=UTF-8';
	}
	$.ajax(reqObj);
}

// ajax提交(默认get方式提交)
function request(options) {
	ajax(options);
}
/**
 *	数据列表
 */

$.fn.getList = function(options, callFun) {
	var search = {},
		screen = {},
		order = {},
		config = {},
		sz,
		pg = {};
	var opts = $.extend({}, options);
	var data = $.extend({}, opts.initData);
	console.log("data="+data);
	var isPage = true;
	if (opts == {}) {
		$('.tipbox').showTips({
			text: '表格配置有误，请检查表格配置',
			type: 'error'
		});
		return false;
	}
	if (opts.isPage == false) {
		isPage = false;
	}
	var _this = $(this);
	var doSearch = function(p) {
		$('.chk.all').find('input').prop('checked', false);
		var h = '';
		var sessionKey = _this.attr('storage') + 'pageSize';
		console.log("sessionKey="+sessionKey);
		sz = window.localStorage.getItem(sessionKey) || opts.initData.size; //获得表格分页数据
		var stgPage = window.sessionStorage.getItem(_this.attr('storage') + 'pageNum');
		if (p) {
			window.sessionStorage.setItem(_this.attr('storage') + 'pageNum', p);
		}
		_this.find('.pageSize').children('.ps').text(sz);
		if (isPage) {
			// data['num'] = p || stgPage || data.num || 1;   解决分页bug
			data['num'] = p || data.num || 1;
			console.log("p="+p);
			console.log("stgPage="+stgPage);
			console.log("data.num="+data.num)
			data['size'] = sz || 10;
		}
		url = opts.url;
		var fullData = {};
		request({
			url: url,
			data: data,
			contentType: opts.contentType || '',
			ajaxform: opts.ajaxform || '',
			type: opts.type,
			callback: function(r) {
				var d = r.result || r.data;
				pg = d;
				if (r.code != 'rest.success') {
					_this.find('.lbox').showTips({
						text: r.code + ':' + (r.msg || r.desc),
						type: 'error'
					});
					ly.alert(r.msg || r.desc, function() {
						ly.goto(site.interUrl + 'login.html');
					});
					return;
				}
				fullData = d.list;
				if (isPage && d.list == undefined) {
					$('.tipbox').showTips({
						text: '数据结构有误，请检查数据list是否存在',
						type: 'error'
					});
					return;
				} else if (!isPage) {
					fullData = d;
				}
				h += '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr gutter = "20">';
				var cols = 0;
				if (opts.checkname != undefined && opts.checkname != '') {
					//选择列
					h += '<th class="w70">&nbsp;</th>';
					cols += 1;
				}
				$.each(opts.col, function(i, e) {
					//表头
					if (e.width != undefined && e.width != '') {
						st = 'col-' + e.width;
					} else {
						st = '';
					}
					h += '<th class = "' + st + '">' + e.display + '</th>';
					cols += 1;
				});
				if (opts.option != undefined && opts.option != '') {
					//操作列
					h += '<th class="w70">操作</th>';
					cols += 1;
				}
				h += '</tr>';
				$.each(fullData, function(j, f) {
					h += '<tr gutter = "20">';
					if (opts.checkname != undefined && opts.checkname != '') {
						h +=
							'<td><div class="chk"><input type="checkbox" name="' +
							opts.checkname +
							'" value = "' +
							f.id +
							'"';
						if (opts.checkattr != undefined && opts.checkattr != '') {
							$.each(opts.checkattr, function(k, g) {
								if (g.value != undefined && g.value != '') {
									var item = g.value.split(','),
										uu = new Array(),
										gname = new Array(),
										gattr = '';
									$.each(item, function(a, z) {
										uu[a] = z.match(/\{\{(.+?)\}\}/g);
										if (uu[a] != '' && uu[a] != null) {
											uu[a] = uu[a].toString();
											gname[a] = uu[a].substring(2, uu[a].length - 2);
											gattr += z.replace(uu[a], f[gname[a]]);
										} else {
											gattr = z;
										}
										if (a < item.length - 1) {
											gattr += ',';
										}
									});
									h += g.attr + '="' + gattr + '"';
								}
							});
						}
						h += '><b></b></div></td>';
					}
					$.each(opts.col, function(i, e) {
						var ff = getter(f, e.field) != undefined ? getter(f, e.field) : '';
						if (e.show != undefined && e.show !== '') {
							$.each(e.show, function(k, g) {
								if (ff == g.value) {
									h += '<td>' + g.html + '</td>';
								}
							});
						} else if (e.fun != undefined && e.fun !== '') {
							h += '<td dofun="' + e.fun + '" row="' + j + '">' + ff + '</td>';
						} else {
							var bf = e.prefix || '';
							var af = e.suffix || '';
							h += '<td>' + bf + ff + af + '</td>';
						}
					});
					if (opts.option != undefined && opts.option != '') {
						//操作列
						h += '<td><label class="operation" title="操作"><ul class="operlist">';
						$.each(opts.option, function(k, g) {
							var vb = disp(g.visible);
							if (g.url != undefined && g.url != '') {
								var item = g.url.split('&'),
									uu = new Array(),
									gname = new Array(),
									gurl = '';
								$.each(item, function(a, z) {
									uu[a] = z.match(/\{\{(.+?)\}\}/g);
									if (uu[a] != '' && uu[a] != null) {
										uu[a] = uu[a].toString();
										gname[a] = uu[a].substring(2, uu[a].length - 2);
										gurl += z.replace(uu[a], f[gname[a]]);
									} else {
										gurl += z;
									}
									if (a < item.length - 1) {
										gurl += '&';
									}
								});
								h +=
									'<li class="' +
									g.icon +
									'" goto="' +
									gurl +
									'" title=' +
									g.tip +
									' style="display:' +
									vb +
									'">';
							} else if (g.fun != undefined && g.fun != '') {
								var item = g.fun.split(','),
									uu = new Array(),
									gname = new Array(),
									gfun = '';
								$.each(item, function(a, z) {
									uu[a] = z.match(/\{\{(.+?)\}\}/g);
									if (uu[a] != null) {
										uu[a] = uu[a].toString();
										if (uu[a] != '') {
											gname[a] = uu[a].substring(2, uu[a].length - 2);
											gfun += z.replace(uu[a], f[gname[a]]);
										}
									} else {
										gfun += z;
									}
									if (a < item.length - 1) {
										gfun += ',';
									}
								});

								h +=
									'<li class="' +
									g.icon +
									'" onclick="' +
									gfun +
									'" title=' +
									g.tip +
									' style="display:' +
									vb +
									'">';
							} else {
								h += '<li class="' + g.icon + '" title=' + g.tip + ' style="display:' + vb + '">';
							}
							if (g.list != undefined && g.url != '') {
								h += '<span class="menulist">';
								$.each(g.list, function(l, ht) {
									if (ht.display == '--') {
										h += '<span>' + ht.display + '</span>';
									} else if (ht.url != undefined && ht.url != '') {
										var htitem = ht.url.split('&'),
											htuu = new Array(),
											htname = new Array(),
											hturl = '';
										$.each(htitem, function(a, z) {
											htuu[a] = z.match(/\{\{(.+?)\}\}/g);
											if (htuu[a] != '' && htuu[a] != null) {
												htuu[a] = htuu[a].toString();
												htname[a] = htuu[a].substring(2, htuu[a].length - 2);
												hturl += z.replace(htuu[a], f[htname[a]]);
											} else {
												hturl += z;
											}
											if (a < htitem.length - 1) {
												hturl += '&';
											}
										});
										h += '<span goto="' + hturl + '">' + ht.display + '</span>';
									} else if (ht.fun != undefined && ht.fun != '') {
										var item = ht.fun.split(','),
											htuu = new Array(),
											htname = new Array(),
											htfun = '';
										$.each(item, function(a, z) {
											htuu[a] = z.match(/\{\{(.+?)\}\}/g);
											if (htuu[a] != null) {
												htuu[a] = htuu[a].toString();
												htname[a] = htuu[a].substring(2, htuu[a].length - 2);
												htfun += z.replace(htuu[a], f[htname[a]]);
											} else {
												htfun += z;
											}
											if (a < item.length - 1) {
												htfun += ',';
											}
										});
										h += '<span onclick="' + htfun + '">' + ht.display + '</span>';
									}
								});
								h += '</span>';
							}
							h += '</li>';
						});
						h += '</ul></label></td>';
					}
					h += '</tr>';
				});
				$('.datafooter').show();
				if (d.length == 0 || (d.list && d.list.length == 0) || (d.list && d.list[0] == null)) {
					h +=
						'<tr gutter = "20"><td class="nodata" colspan="' +
						cols +
						'" align="center">没有查询到相关数据</td></tr>';
					_this.find('.datafooter').hide();
				}
				h += '</table>';
				_this.find('.lbox').html(h);
				$('.right_con').animate(
					{
						scrollTop: 0
					},
					100
				);
				_this.find('.lbox').find('td[dofun]').each(function() {
					var row = $(this).attr('row');
					var text = $(this).text();
					text = text.replace(/(\n)/g, '');
					text = text.replace(/(\t)/g, '');
					text = text.replace(/(\r)/g, '');
					text = text.replace(/<\/?[^>]*>/g, '');
					text = text.replace(/\s*/g, '');
					eval($(this).attr('dofun') + "('" + text + "',this,fullData[row])");
				});
				if (typeof opts.callback == 'function') {
					opts.callback(fullData, _this);
				}
				//分页处理
				p = _this.find('.pager');
				if (isPage) {
					p.html(
						'<div class="fl">共<span>' +
							d.total +
							'</span>条记录&nbsp;&nbsp;每页显示<span class="pageSize"><span class="ps">' +
							sz +
							'</span>条<span class="size"><em><i>5</i>条</em><em><i>10</i>条</em><em><i>20</i>条</em><em><i>50</i>条</em><em><i>100</i>条</em><em><i>200</i>条</em></span></span>&nbsp;&nbsp;第<span class="page">' +
							d.pageNum +
							'</span>/<span class="pageCount">' +
							d.pages +
							'</span>页</div><div class="fr"><button class="first" disabled></button><button class="prev" disabled></button><button class="next"></button><button class="last"></button></div>'
					);
				} else {
					_this.find('.pager').remove();
				}
				p.find('.chk.all>input').removeAttr('checked');
				p.find('button').unbind('click');
				p.find('button').removeAttr('disabled');
				p.find('.next').click(function() {
					doSearch(d.pageNum + 1);
				});
				p.find('.prev').click(function() {
					doSearch(d.pageNum - 1);
				});
				p.find('.first').click(function() {
					doSearch(1);
				});
				p.find('.last').click(function() {
					doSearch(d.pages);
				});
				if (d.pageNum >= d.pages) {
					p.find('.next,.last').attr('disabled', true);
				}
				if (d.pageNum <= 1) {
					p.find('.first,.prev').attr('disabled', true);
				}
				p.find('.pageSize').unbind('click');
				p.unbind('click');
				p.on('click', 'em', function() {
					var stor = _this.attr('storage');
					var ssz = $(this).children('i').text();
					window.localStorage.setItem(stor + 'pageSize', ssz);
					p.find('.pageSize').children('.ps').text(ssz);
					doSearch(1);
				});
				//间距处理
				_this.find('[gutter]').each(function() {
					var m = $(this).attr('gutter') || 0;
					var w = $(this).width();
					$(this).children().css({
						'padding-left': m / 2,
						'padding-right': m / 2
					});
					$(this).css({
						'margin-left': -m / 2,
						'margin-right': -m / 2
					});
				});
				$('.menulist').each(function() {
					var obj = $(this);
					var r = window.location.search.substr(1);
					var u;
					obj.find('a').each(function() {
						u = $(this).attr('href');
						if (u.match('[?]')) {
							$(this).attr('href', u + '&' + r);
						} else {
							$(this).attr('href', u + '?' + r);
						}
					});
					$(this).find('span').each(function() {
						if ($(this).text() == '--') {
							$(this).height(1).text('').css('border-bottom', '1px solid #dcdcdc');
						}
					});
				});
				_this.getOper(); //获得操作按钮
				if (typeof callFun == 'function') {
					callFun();
				}
			}
		});
	};
	$.fn.getList.setBackData = function(initData) {
		data = $.extend({}, data, initData);
	};
	$.fn.getList.setData = function(initData) {
		data = $.extend({}, data, initData);
		doSearch();
	};
	$.fn.getList.refresh = function() {
		doSearch(pg.num);
	};
	$(this).find('.pageSize .ps').text(sz);
	var sc = $($(this).attr('data-sc'));
	var _this = $(this);
	if (opts.ignoreWidth) {
		_this.find('.lbox').css({
			'white-space': 'nowrap',
			'overflow-x': 'auto'
		});
	}
	var w = new Array();
	doSearch();
	sc.find('[main]').unbind('click');
	sc.find('[main]').click(function(s) {
		sc.find('[search-obj]').each(function() {
			if ($(this).attr('ly-type') == 'radio') {
				var w = $(this).attr('search-obj');
				search[w] = $.trim($(this).find('[type=radio]:checked').val());
			} else if ($(this).attr('ly-type') == 'checkbox') {
				var cv = '';
				var _obj = $(this);
				_obj.find('input:checked').each(function(i) {
					if (i < _obj.find('input:checked').length - 1) {
						cv += $.trim($(this).val()) + ',';
					} else {
						cv += $.trim($(this).val());
					}
				});
				search[_obj.attr('search-obj')] = cv || '';
			} else if ($(this).attr('ly-type') == 'select') {
				var cv = '';
				// var _obj = $(this).find("select");
				cv = $.trim($(this).val());
				search[$(this).attr('search-obj')] = cv || '';
			} else {
				var w = $(this).attr('search-obj');
				search[w] = $.trim($(this).val());
			}
		});
		sc.find('[screen-obj]').each(function() {
			screen[$(this).attr('screen-obj')] = $.trim($(this).find('input:checked').val()) || '';
		});
		data = $.extend(data, screen, search);
		doSearch(1);
	});
	sc.find('[screen-obj]').unbind('change');
	sc.find('[screen-obj]').on('change', 'input', function() {
		if ($(this).is(':checkbox')) {
			if ($(this).is(':checked')) {
				screen[$(this).parents('[screen-obj]').attr('screen-obj')] = $(this).val();
			} else {
				screen[$(this).parents('[screen-obj]').attr('screen-obj')] = '';
			}
		} else {
			screen[$(this).parents('[screen-obj]').attr('screen-obj')] = $(this).val();
		}
		data = $.extend(data, screen, search);
		doSearch(1);
	});
	lyComplete();
};

/**
 * 权限列表
 */

$.fn.getChannelList = function(options) {
	var search = {},
		screen = {},
		order = {},
		config = {},
		sz,
		pg = {};
	var opts = $.extend({}, options);
	var data = $.extend({}, opts.initData);
	if (opts == {}) {
		$('.tipbox').showTips({
			text: '表格配置有误，请检查表格配置',
			type: 'error'
		});
		return false;
	}
	var $current = '';
	var _this = $(this);
	var fullData = {};
	initChannel(1);

	function initChannel(p) {
		var h = '';
		if (!$current) {
			sz = window.localStorage.getItem(_this.attr('storage') + 'pageSize') || opts.initData.size; //获得表格分页数据
			_this.find('.pageSize').children('.ps').text(sz);
			data['num'] = p || data.num || 1;
			data['size'] = sz || 10;
		}
		$('body').showloading({
			parent: true
		});

		url = opts.url;
		var param = data;
		if ($current) {
			param.id = $current.attr('cid');
		}
		param.size = options.initData.size == '' ? '' : param.size;

		request({
			url: url,
			data: param,
			type: opts.type,
			ajaxform: opts.ajaxform || '',
			callback: function(r) {
				if (!$current) {
					pg = r.result;
				}
				if (r.code != 'rest.success') {
					_this.find('.lbox').showTips({
						text: r.code + ':' + r.msg,
						type: 'error'
					});
					return;
				}
				if (!r.result) {
					$('.tipbox').showTips({
						text: '数据结构有误，请检查数据list是否存在',
						type: 'error'
					});
					return;
				}
				if (!$current) {
					h += '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr gutter = "20">';
					var cols = 0;
					$.each(opts.col, function(i, e) {
						//表头
						if (e.width != undefined && e.width != '') {
							st = 'col-' + e.width;
						} else {
							st = '';
						}
						h += '<th class = "' + st + '">' + e.display + '</th>';
						cols += 1;
					});

					if (opts.option != undefined && opts.option != '') {
						//操作列
						h += '<th class="w70">操作</th>';
						cols += 1;
					}
					h += '</tr>';
				}

				var l = '';
				var series = $current ? $current.attr('name').split('_').length : 0;
				var flagClass = '';
				$.each(r.result.list, function(i, items) {
					var cClass = $current ? $current.attr('name') + '_1' : 'chaannel' + i;
					l +=
						'<tr cid="' +
						items.id +
						'" name="' +
						cClass +
						'" isleaf="' +
						(items.parentNum == 0 ? 'false' : 'true') +
						'" gotter = "0,0">';
					var dis = items.parentNum == 0 ? 'hide' : '';
					var dis1 = items.parentNum == 0 ? 'vish' : '';
					$.each(opts.col, function(j, e) {
						var space = j == 0 ? 'gotter = "' + (series + 1) * 40 + ',20"' : 'gotter = "20,20"';
						var i_icon = j == 0 ? '<b class="i-expand ' + ($current ? dis : dis1) + '"></b>' : '';
						var ff = getter(items, e.field) != undefined ? getter(items, e.field) : '';
						if (e.show != undefined && e.show !== '') {
							$.each(e.show, function(k, g) {
								if (ff == g.value) {
									l +=
										'<td ' +
										space +
										'>' +
										i_icon +
										'<div class="lm-expand pl10">' +
										g.html +
										'</div></td>';
								}
							});
						} else if (e.fun != undefined && e.fun !== '') {
							var fdlen = Object.keys(fullData).length;
							fullData[fdlen] = items;
							l +=
								'<td dofun="' +
								e.fun +
								'" row="' +
								fdlen +
								'" ' +
								space +
								'>' +
								i_icon +
								'<div class="lm-expand pl10">' +
								ff +
								'</div></td>';
						} else {
							var bf = e.prefix || '';
							var af = e.suffix || '';
							l +=
								'<td ' +
								space +
								'>' +
								i_icon +
								'<div class="lm-expand pl10">' +
								bf +
								ff +
								af +
								'</div></td>';
						}
					});
					if (opts.option != undefined && opts.option != '') {
						//操作列
						l += '<td><label class="operation" title="操作"><ul class="operlist">';
						$.each(opts.option, function(k, g) {
							var vb = disp(g.visible);
							if (g.url != undefined && g.url != '') {
								var item = g.url.split('&'),
									uu = [],
									gname = [],
									gurl = '';
								$.each(item, function(a, z) {
									uu[a] = z.match(/\{\{(.+?)\}\}/g);
									if (uu[a] != '' && uu[a] != null) {
										uu[a] = uu[a].toString();
										gname[a] = uu[a].substring(2, uu[a].length - 2);
										gurl += z.replace(uu[a], items[gname[a]]);
									} else {
										gurl += z;
									}
									if (a < item.length - 1) {
										gurl += '&';
									}
								});
								l +=
									'<li class="' +
									g.icon +
									'" goto="' +
									gurl +
									'" title=' +
									g.tip +
									' style="display:' +
									vb +
									'">';
							} else if (g.fun != undefined && g.fun != '') {
								var item = g.fun.split(','),
									uu = [],
									gname = [],
									gfun = '';
								$.each(item, function(a, z) {
									uu[a] = z.match(/\{\{(.+?)\}\}/g);
									if (uu[a] != null) {
										uu[a] = uu[a].toString();
										if (uu[a] != '') {
											gname[a] = uu[a].substring(2, uu[a].length - 2);
											gfun += z.replace(uu[a], items[gname[a]]);
										}
									} else {
										gfun += z;
									}
									if (a < item.length - 1) {
										gfun += ',';
									}
								});
								l +=
									'<li class="' +
									g.icon +
									'" onclick="' +
									gfun +
									'" title=' +
									g.tip +
									' style="display:' +
									vb +
									'">';
							} else {
								l += '<li class="' + g.icon + '" title=' + g.tip + ' style="display:' + vb + '">';
							}
							if (g.list != undefined && g.url != '') {
								l += '<span class="menulist">';
								$.each(g.list, function(ls, ht) {
									if (ht.display == '--') {
										l += '<span>' + ht.display + '</span>';
									} else if (ht.url != undefined && ht.url != '') {
										var htitem = ht.url.split('&'),
											htuu = [],
											htname = [],
											hturl = '';
										$.each(htitem, function(a, z) {
											htuu[a] = z.match(/\{\{(.+?)\}\}/g);
											if (htuu[a] != '' && htuu[a] != null) {
												htuu[a] = htuu[a].toString();
												htname[a] = htuu[a].substring(2, htuu[a].length - 2);
												hturl += z.replace(htuu[a], items[htname[a]]);
											} else {
												hturl += z;
											}
											if (a < htitem.length - 1) {
												hturl += '&';
											}
										});
										l += '<span goto="' + hturl + '">' + ht.display + '</span>';
									} else if (ht.fun != undefined && ht.fun != '') {
										var item = ht.fun.split(','),
											htuu = [],
											htname = [],
											htfun = '';
										$.each(item, function(a, z) {
											htuu[a] = z.match(/\{\{(.+?)\}\}/g);
											if (htuu[a] != null) {
												htuu[a] = htuu[a].toString();
												htname[a] = htuu[a].substring(2, htuu[a].length - 2);
												htfun += z.replace(htuu[a], items[htname[a]]);
											} else {
												htfun += z;
											}
											if (a < item.length - 1) {
												htfun += ',';
											}
										});
										l += '<span onclick="' + htfun + '">' + ht.display + '</span>';
									}
								});
								l += '</span>';
							}
							l += '</li>';
						});
						l += '</ul></label></td>';
					}
					l += '</tr>';
				});
				if (options.initData.size == '') {
					$('.datafooter').hide();
				} else {
					$('.datafooter').show();
				}
				if ($current) {
					$current.find('b.i-expand').addClass('i-zhankai').removeClass('i-expand');
					$current.after(l);
				} else {
					h += l;
					if (r.result.list.length == 0) {
						h +=
							'<tr gutter = "20"><td class="nodata" colspan="' +
							cols +
							'" align="center">暂无相关数据</td></tr>';
						$('.datafooter').hide();
					}
					h += '</table>';
					_this.find('.lbox').html(h);
				}
				_this.find('.lbox').find('td[dofun]').each(function() {
					var row = $(this).attr('row');
					eval(
						$(this).attr('dofun') +
							"('" +
							$(this).children('.lm-expand').text() +
							"',$(this).children('.lm-expand')[0],fullData[row])"
					);
				});
				if (typeof opts.callback == 'function') {
					opts.callback(fullData, _this);
				}

				//间距处理
				_this.find('[gutter]').each(function() {
					var m = $(this).attr('gutter') || 0;
					var w = $(this).width();
					$(this).children().css({
						'padding-left': m / 2,
						'padding-right': m / 2
					});
					$(this).css({
						'margin-left': -m / 2,
						'margin-right': -m / 2
					});
				});
				_this.find('[gotter]').each(function() {
					var m = $(this).attr('gotter') || '0,0';
					var arry = m.split(',');
					$(this).css({
						'padding-left': arry[0] / 2,
						'padding-right': arry[1] / 2
					});
				});
				$('.menulist').each(function() {
					var obj = $(this);
					var r = window.location.search.substr(1);
					var u;
					obj.find('a').each(function() {
						u = $(this).attr('href');
						if (u.match('[?]')) {
							$(this).attr('href', u + '&' + r);
						} else {
							$(this).attr('href', u + '?' + r);
						}
					});
					$(this).find('span').each(function() {
						if ($(this).text() == '--') {
							$(this).height(1).text('').css('border-bottom', '1px solid #dcdcdc');
						}
					});
				});
				_this.getOper(); //获得操作按钮
				if (!$current) {
					//分页处理
					p = _this.find('.pager');
					p.html(
						'<div class="fl">共<span>' +
							pg.total +
							'</span>条记录&nbsp;&nbsp;每页显示<span class="pageSize"><span class="ps">' +
							sz +
							'</span>条<span class="size"><em><i>5</i>条</em><em><i>10</i>条</em><em><i>20</i>条</em><em><i>50</i>条</em><em><i>100</i>条</em><em><i>200</i>条</em></span></span>&nbsp;&nbsp;第<span class="page">' +
							pg.pageNum +
							'</span>/<span class="pageCount">' +
							pg.pages +
							'</span>页</div><div class="fr"><button class="first" disabled></button><button class="prev" disabled></button><button class="next"></button><button class="last"></button></div>'
					);
					p.find('.chk.all>input').removeAttr('checked');
					p.find('button').unbind('click');
					p.find('button').removeAttr('disabled');
					p.find('.next').click(function() {
						fullData = {};
						initChannel(pg.pageNum + 1);
					});
					p.find('.prev').click(function() {
						fullData = {};
						initChannel(pg.pageNum - 1);
					});
					p.find('.first').click(function() {
						fullData = {};
						initChannel(1);
					});
					p.find('.last').click(function() {
						fullData = {};
						initChannel(pg.pages);
					});
					if (pg.pageNum >= pg.pages) {
						p.find('.next,.last').attr('disabled', true);
					}
					if (pg.pageNum <= 1) {
						p.find('.first,.prev').attr('disabled', true);
					}
					p.find('.pageSize').unbind('click');
					p.unbind('click');
					p.on('click', 'em', function() {
						var stor = _this.attr('storage');
						var ssz = $(this).children('i').text();
						window.localStorage.setItem(stor + 'pageSize', ssz);
						p.find('.pageSize').children('.ps').text(ssz);
						fullData = {};
						initChannel(1);
					});
				}
				$current = '';
				data.id = '';
			}
		});
	}
	$.fn.getChannelList.setData = function(initData) {
		data = $.extend({}, data, initData);
		fullData = {};
		initChannel();
	};
	$.fn.getChannelList.refresh = function() {
		fullData = {};
		initChannel(pg.num);
	};
	_this.find('.lbox').on('click', 'tr[isleaf="true"]', function(e) {
		var o = e.target;
		if ($(o).closest('.icon-shanchu1,.icon-xitong,.icon-add').length == 0) {
			if ($(this).find('b.i-zhankai').length == 1) {
				var nameClass = $(this).attr('name');
				$(this).nextAll('[name^="' + nameClass + '_1"]').remove();
				$(this).find('b.i-zhankai').addClass('i-expand').removeClass('i-zhankai');
				return;
			}
			$current = $(this);
			initChannel(pg.pageNum);
		}
	});
};

/**
 *	表单数据绑定
 */
$.fn.getForm = function(fdata, callback, childform) {
	var _this = $(this);
	var url = $(this).attr('ly-get') || fdata.changeUrl;
	if (url != '' && url != undefined) {
		var u = url.match(/\{\{(.+?)\}\}/g);
		if (u != '' && u != undefined) {
			var um = u.toString();
			var up = um.substring(2, um.length - 2);
			var uu = site[up];
			url = url.replace(um, uu);
		}
	} else {
		url = '';
	}
	var data = fdata || {},
		o,
		p,
		tp;
	var contentType = data.contentType || '';
	var ajaxform = data.ajaxform || '';
	var loading = data.loading || '';
	var type = data.type || 'get';
	delete data.url;
	delete data.contentType;
	delete data.ajaxform;
	delete data.loading;
	delete data.type;
	request({
		url: url,
		data: data,
		contentType: contentType,
		ajaxform: ajaxform,
		type: type,
		loading: loading,
		callback: function(r) {
			if (r.code != 'rest.success') {
				_this.find('.tipbox').showTips({
					text: r.code + ':' + r.msg,
					type: 'error'
				});
				_this.find('.infoBox').hide();
				return;
			}
			var d = r.result;
			if (d instanceof Array) {
				if (childform == '' || childform == undefined) {
					_this.parents('.card').find('.tipbox').ly.toast('getForm配置有误，结果疑似多个表单数组结构，但未配置“childform”参数');
				} else {
					$.each(d, function(i, c) {
						childform.eq(i).databind({
							bdata: c,
							callback: callback
						});
					});
				}
			} else {
				_this.databind({
					bdata: d,
					callback: callback
				});
			}
		}
	});
};

/**
 *	数据绑定
 */
var px = 100;
$.fn.databind = function(options) {
	var defaults = {
		bdata: '',
		callback: ''
	};
	var opts = $.extend({}, defaults, options);
	var obj = $(this);
	var d = opts.bdata;
	var _this = $(this);
	var g = 0;
	var n = 0;
	obj.find('[ly-bind]').each(function() {
		o = $(this).attr('ly-bind');
		tp = $(this).attr('ly-type');
		p = getter(d, o) != undefined ? getter(d, o) : '';
		if (($(this).is('input') && $(this).attr('type') != 'upvideo') || $(this).is('textarea')) {
			if (p == 0 || p != '') {
				$(this).val(p);
			}
		} else if (typeof $(this).attr('ly-ueidtor') != 'undefined') {
			$(this).html(p);
		} else if (tp == 'radio' || tp == 'checkbox' || tp == 'select' || tp == 'screen' || tp == 'tree') {
			g++;
			if (p != null && p != undefined) {
				$(this).attr('ly-val', p);
			}
			var name = $(this).attr('name');
			var code = $(this).attr('ly-code') || '';
			var val = $(this).attr('ly-val');
			var dis = $(this).attr('disabled') ? true : false;
			var list = $(this).attr('ly-list') || '';
			var max = $(this).attr('max-item');
			var onlyLeaf = $(this).attr('onlyLeaf') != undefined ? true : false;
			if (list != '' && list != undefined) {
				list = JSON.parse(list);
			}
			$(this).getSelect(
				{
					type: tp,
					asName: name,
					code: code,
					default: val,
					list: list,
					disabled: dis,
					maxlength: max,
					onlyLeaf: onlyLeaf
				},
				function() {
					n++;
				}
			);
		} else if ($(this).attr('filetype') == 'images') {
			var h = '';
			var img;
			var uploader_filename = new Array();
			var dis = $(this).attr('disabled') == undefined;
			if (p instanceof Array) {
				$.each(p, function(p, e) {
					//给隐藏信息赋值
					img = e;
					if ($(this).attr('disabled') != undefined) {
					} else {
						h +=
							'<div id="WU_FILE_' +
							px +
							'" class="file-item upload-state-done"><img src="' +
							img.url +
							'"><input type="hidden" class="filepath" value="' +
							img.filePath +
							'" fileName="' +
							img.fileName +
							'" fileSize="' +
							img.fileSize +
							'" fileType="' +
							img.fileType +
							'"><div class="info"></div><div class="cancel"><i class="iconfont icon-shanchu1"></i></div><div class="success"></div></div>';

						// h += '<div id="WU_FILE_' + px + '" class="file-item upload-state-done"><img src="' + e + '"><input type="hidden" class="filepath" value="' + e + '" ><div class="info"></div><div class="cancel"><i class="iconfont icon-shanchu1"></i></div><div class="success"></div></div>';
					}
					uploader_filename.push(e);
					px++;
				});
			} else if (p) {
				h +=
					'<div id="WU_FILE_' +
					px +
					'" class="file-item upload-state-done"><img src="' +
					p.url +
					'"><input type="hidden" class="filepath" value="' +
					p.filePath +
					'" fileName="' +
					p.fileName +
					'" fileSize="' +
					p.fileSize +
					'" fileType="' +
					p.fileType +
					'"><div class="info"></div><div class="cancel"><i class="iconfont icon-shanchu1"></i></div><div class="success"></div></div>';
				uploader_filename.push(p);
				px++;
			}
			$(this).find('.uploadvalid').val(uploader_filename);
			$(this).find('.file-list').prepend(h);
		} else if ($(this).attr('filetype') == '*' || $(this).attr('filetype') == 'audio') {
			var h = '';
			var img;
			var uploader_filename = new Array();
			if (p instanceof Array) {
				$.each(p, function(p, e) {
					//给隐藏信息赋值
					img = e;
					h +=
						'<div id="WU_FILE_' +
						px +
						'" class="file-item annex-item upload-state-done"><input type="hidden" class="filepath" value="' +
						img.filePath +
						'" fileName="' +
						img.fileName +
						'" fileSize="' +
						img.fileSize +
						'" fileType="' +
						img.fileType +
						'" businessCode="' +
						img.businessCode +
						'"><div class="info"><i class="iconfont-guangming icon-iconfontfile"></i>附件：《' +
						img.fileName +
						'》</div><div class="cancel"><span>删除</span></div></div>';
					uploader_filename.push(img.fileName);
					px++;
				});
			} else if (p) {
				h +=
					'<div id="WU_FILE_' +
					px +
					'" class="file-item annex-item upload-state-done"><input type="hidden" class="filepath" value="' +
					p.filePath +
					'" fileName="' +
					p.fileName +
					'" fileSize="' +
					p.fileSize +
					'" fileType="' +
					p.fileType +
					'" businessCode="' +
					p.businessCode +
					'"><div class="info"><i class="iconfont-guangming icon-iconfontfile"></i>附件：《' +
					p.fileName +
					'》</div><div class="cancel"><span>删除</span></div></div>';
				uploader_filename.push(p.fileName);
				px++;
			}
			$(this).find('.uploadvalid').val(uploader_filename);
			$(this).find('.file-list').prepend(h);
		} else if (tp == 'upimg') {
			if (p != '' && p != undefined) {
				var img = p;
				$(this).find('input[type=hidden]').val(img.filePath).attr({
					fileName: img.fileName,
					fileSize: img.fileSize,
					fileType: img.fileType,
					businessCode: img.businessCode
				});
				$(this).find('.imgbox').html('<img src="' + img.url + '"></div>');
				$(this).addClass('active');
			}
		} else if ($(this).attr('type') == 'upvideo') {
			if (p != '' && p != undefined) {
				var video = p;
				$(this).val(video.filePath).attr({
					fileName: video.fileName,
					fileSize: video.fileSize,
					fileType: 2,
					fileUrl: video.url
				});
				if (video.url) {
					$(this).siblings('.videobox').find('video').attr('src', video.url);
					$(this).siblings('.videobox').addClass('active');
				}
			}
		} else if (tp != undefined && tp.split(':')[0] == 'fun') {
			eval(tp.split(':')[1] + "('" + p + "',this)");
		} else if (tp == 'img') {
			var imgitem = '';
			//判断是否位数组
			if (p instanceof Array) {
				$(p).each(function(i) {
					imgitem += '<div class="file-item mt0"><img src=' + p[i].url + '></div>';
				});
			} else if (p.url != '' && p.url != undefined) {
				imgitem += '<div class="file-item b0"><img src=' + p.url + '></div>';
			} else {
				imgitem += '<div>未上传图片</div>';
			}
			$(this).html(imgitem);
		} else if (tp == 'textgroup') {
			p = p.split(',');
			$(this).find('input').each(function(i) {
				$(this).val(p[i]);
			});
		} else if (tp == 'file') {
			//附件查看显示
			var fileitem = '';
			//判断是否位数组
			if (p instanceof Array) {
				$(p).each(function(i) {
					if (p[i].fileName) {
						fileitem +=
							'<div class="file-item annex-item"><div class="info"><i class="iconfont-guangming icon-iconfontfile"></i>附件：《' +
							p[i].fileName +
							'》</div></div>';
					}
				});
			} else {
				if (p.fileName) {
					fileitem +=
						'<div class="file-item annex-item"><div class="info"><i class="iconfont-guangming icon-iconfontfile"></i>附件：《' +
						p.fileName +
						'》</div></div>';
				} else {
					fileitem += '未上传附件';
				}
			}
			$(this).html(fileitem);
		} else if (tp == 'text') {
			if ($(this).attr('unit')) {
				$(this).html(p + $(this).attr('unit'));
			} else {
				$(this).html(p);
			}
		} else if (tp == 'upvideo') {
			if (p.url) {
				var video = '<video class="videobox" src=' + p.url + ' controls=""></video>';
				$(this).html(video);
			}
		} else if (tp == 'map') {
			if (p != '' && p != undefined) {
				var map = p;
				$(this).find('span').text(map.addrsName);
				$(this).find('label:eq(0)').text(map.longitude);
				$(this).find('label:eq(1)').text(map.latitude);
			}
		} else if (tp == 'showicon') {
			var ii = 'icon';
			if (p.indexOf('icon') > -1) {
				$(this).append('<i class="iconshow iconfont-guangming ' + p + '"></i>');
			} else {
				$(this).append('<i class="iconshow iconfont-guangming">' + p + '</i>');
			}
		}
	});
	if (typeof opts.callback == 'function') {
		var t = setInterval(function() {
			if (g == n) {
				opts.callback(d, _this);
				lyComplete();
				clearInterval(t);
			}
		}, 100);
	} else {
		lyComplete();
	}
};
/**
 *	创建空表单
 */
$.fn.createForm = function(callback) {
	var _this = $(this);
	var g = 0;
	var n = 0;
	_this.find('[ly-bind]').each(function() {
		var tp = $(this).attr('ly-type');
		// console.log(tp)
		if (tp == 'radio' || tp == 'checkbox' || tp == 'select' || tp == 'screen' || tp == 'tree') {
			g++;
			var code = $(this).attr('ly-code');
			var dis = $(this).attr('disabled') ? true : false;
			var list = $(this).attr('ly-list');
			var max = $(this).attr('max-item');
			var onlyLeaf = $(this).attr('onlyLeaf') != undefined ? true : false;
			if (list != '' && list != undefined) {
				list = JSON.parse(list);
			}
			var name = $(this).attr('name');
			// $(this).removeAttr("name");
			$(this).getSelect(
				{
					type: tp,
					asName: name,
					code: code,
					list: list,
					disabled: dis,
					maxlength: max,
					onlyLeaf: onlyLeaf
				},
				function() {
					n++;
				}
			);
		}
	});
	if (typeof callback == 'function') {
		var t = setInterval(function() {
			if (g == n) {
				lyComplete();
				clearInterval(t);
				callback(_this);
			}
		}, 100);
	} else {
		lyComplete();
	}
};

function assignment(obj, path) {
	if (!path) return obj;
	var keys = path.split('.');
	var key;
	var oo = '{"';
	var len = keys.length;
	for (var i = 0; i < len; i++) {
		key = keys[i];
		if (i < len - 1) {
			oo = oo + key + '":{"';
		} else {
			oo = oo + key + '"';
		}
	}
	oo += ':"' + obj + '"';
	for (var i = 0; i < len - 1; i++) {
		key = keys[i].trim();
		oo += '}';
	}
	oo += '}';
	var d = JSON.parse($.trim(oo));
	return d;
}
/**
 *	提交表单
 */
$.fn.submitForm = function(set, goto, altype, submitWord) {
	var _this = $(this);
	_this.siblings('.btnBox').find('.btn').prop('disabled', true);
	_this.parents('.card').showloading();
	var url = set.url || $(this).attr('ly-post');
	var contentType = set.contentType || '';
	var ajaxform = set.ajaxform || '';
	delete set.url;
	delete set.contentType;
	delete set.ajaxform;
	var info = _this.submitData();
	var data = $.extend({}, info, set);
	if (submitWord != '' && submitWord != undefined) {
		var at = {};
		at[submitWord] = data;
		data = at;
	}
	if (url != '' && url != undefined) {
		var u = url.match(/\{\{(.+?)\}\}/g);
		if (u != '' && u != undefined) {
			var um = u.toString();
			var up = um.substring(2, um.length - 2);
			var uu = site[up];
			url = url.replace(um, uu);
		}
	} else {
		url = '';
	}
	request({
		url: url,
		data: data,
		contentType: contentType,
		ajaxform: ajaxform,
		callback: function(r) {
			if (r.code != 'rest.success') {
				ly.alert(r.desc);
				_this.find('.infoBox').hide();
				_this.siblings('.btnBox').find('.btn').prop('disabled', false);
				return;
			} else {
				if (typeof altype == 'function') {
					altype(r);
				} else if (altype === '' || altype === undefined || altype == 'alert') {
					var desc = r.msg || '保存成功';
					ly.alert(desc, function() {
						if (goto != '' && goto != undefined) {
							ly.goto(goto);
						} else {
						}
					});
				} else if (altype == 'toast') {
					ly.toast(r.msg);
					$('body').showloading();
					setTimeout(function() {
						if (goto != '' && goto != undefined) {
							ly.goto(goto);
						}
					}, 1000);
				} else if (altype == 'none') {
					$('body').showloading();
					setTimeout(function() {
						if (goto != '' && goto != undefined) {
							ly.goto(goto);
						}
					}, 1000);
				} else if (altype == 'refresh') {
					ly.alert('保存成功', function() {
						window.location.reload();
					});
				}
			}
		}
	});
};
$.fn.submitData = function(set) {
	var _this = $(this);
	var info = {};
	_this.find('[ly-bind]').each(function() {
		info = $.extend(
			true,
			info,
			assignment(
				$(this).val().replace(/\n/g, '') ||
					$(this).find('select').val() ||
					$(this).find('input:checked').val() ||
					'',
				$(this).attr('ly-bind')
			)
		);
		if ($(this).attr('ly-type') == 'checkbox') {
			var cv = '';
			var _obj = $(this);
			if (_obj.find('input:checked').length > 0) {
				_obj.find('input:checked').each(function(i) {
					if (i < _obj.find('input:checked').length - 1) {
						cv += $(this).val() + ',';
					} else {
						cv += $(this).val();
					}
				});
			} else {
				cv = '';
			}
			info = $.extend(true, info, assignment(cv || '', _obj.attr('ly-bind')));
		}
		if ($(this).attr('ly-type') == 'tree') {
			info = $.extend(
				true,
				info,
				assignment($(this).next('.thisbox').find('.chooseData').attr('data-val') || '', $(this).attr('ly-bind'))
			);
		}
		if ($(this).attr('ly-type') == 'upimg') {
			var tub = {};
			tub.filePath = $(this).find('input').val();
			tub.fileName = $(this).find('input').attr('fileName');
			tub.fileSize = $(this).find('input').attr('fileSize');
			tub.fileType = $(this).find('input').attr('fileType');
			// tub.businessCode = $(this).find("input").attr("businessCode");
			info[$(this).attr('ly-bind')] = tub || '';
		}
		if ($(this).attr('type') == 'simple-uploader' || $(this).attr('type') == 'material-uploader') {
			var iv = new Array();
			$(this).find('.filepath').each(function(i) {
				var o = {
					// 'businessCode': $(this).attr("businessCode"),
					fileType: $(this).attr('fileType'),
					fileName: $(this).attr('fileName'),
					fileSize: $(this).attr('fileSize'),
					filePath: $(this).val()
				};
				iv.push(o);
			});
			info[$(this).attr('ly-bind')] = iv || '';
		}
		if ($(this).attr('ly-type') == 'textgroup') {
			var tv = '';
			var _obj = $(this);
			_obj.find('input').each(function(i) {
				if (i < _obj.find('input').length - 1) {
					tv += $(this).val() + ',';
				} else {
					tv += $(this).val();
				}
			});
			info = $.extend(true, info, assignment(tv || '', _obj.attr('ly-bind')));
		}
	});
	var data = $.extend({}, info, set);
	return data;
};
//菜单，功能权限树
$.fn.permissionList = function(options) {
	var _this = $(this);
	var defaults = {
		echodataMenu: [],
		echodataFunc: []
	};
	var opts = $.extend({}, defaults, options);
	var ranflag = Uniquestring('ranflag');
	var funclist = [];
	_this.html('');
	_this.append(
		'<div class="' +
			ranflag +
			'"><p><span>菜单：</span><label class="pr20 menus">0</label><button class="btn body-submit red clears">清空</button></p><div class="permission-container"></div></div>'
	);
	$('.' + ranflag + ' .permission-container').siblings('p').css('color', '#444');
	$('.' + ranflag + ' .permission-container')
		.on('click', 'li', function(event) {
			stopBubble(event);
			var o = event.target;
			var $this = $(this);
			if ($(o).closest('i.icon-expand,i.icon-zhankai').length == 0) {
				$this.toggleClass('choosed');
				$('.' + ranflag + ' .permission-container li').children('i.icon-qiyong').removeClass('half-chos');
				if ($this.hasClass('choosed')) {
					$this.parents('ul.child-list').prev('li').addClass('choosed');
					$this.next('ul').find('li').addClass('choosed');
				} else {
					$this.next('ul').find('li').removeClass('choosed');
				}
				$('.' + ranflag + ' .menus').text($('.' + ranflag + ' .mens.choosed').length);
				$('.' + ranflag + ' .functions').text($('.' + ranflag + ' .funs.choosed').length);
				selectedOpts();
			} else {
				if ($this.hasClass('open')) {
					$this.removeClass('open');
					$this.children('.icon-zhankai').removeClass('icon-zhankai').addClass('icon-expand');
					$this.next('ul.child-list').hide();
				} else {
					$this.addClass('open');
					$this.children('.icon-expand').removeClass('icon-expand').addClass('icon-zhankai');
					if ($this.next('ul').hasClass('child-list')) {
						$this.next('ul.child-list').show();
					} else {
						ly.toast('该菜单下暂无项目');
					}
				}
				$('.' + ranflag + ' .permission-container').getNiceScroll().resize();
			}
		})
		.siblings('p')
		.on('click', '.clears', function() {
			if ($('.' + ranflag + ' .menus').text() == '0' && $('.' + ranflag + ' .functions').text() == '0') {
				ly.toast('已清空，请勿重复操作');
				return;
			}
			$('.' + ranflag + ' li.choosed').removeClass('choosed');
			$('.' + ranflag + ' .menus').text(0);
			$('.' + ranflag + ' .functions').text(0);
		});
	$.fn.permissionList.returndata = function() {
		var returndata = { menu: [], fun: [] };
		$.each($('.' + ranflag + ' .mens.choosed'), function(i, item) {
			returndata.menu.push($(item).attr('data-id'));
		});
		$.each($('.' + ranflag + ' .funs.choosed'), function(j, items) {
			returndata.fun.push($(items).attr('data-id'));
		});
		return returndata;
	};
	$('.' + ranflag + ' .permission-container').html(
		'<div class="loadings f16 pl10 c_444"><label class="pr10">数据正在加载中</label><img class="v-a-middle" src="' +
			site.interUrl +
			'/img/loading.gif"></div>'
	);
	request({
		url: site.apiUrl + '/menu/selectMenuAllThisScenicLowerLevelAdminMenu',
		type: 'POST',
		ajaxform: true,
		callback: function(r) {
			if (r.code == 'rest.success') {
				var data = r.result;
				if (data.menu.length > 0 && data.menu[0]['m1'].length > 0) {
					if ($('#jquery_nicescroll').length == 0) {
						$('body').append(
							'<script id="jquery_nicescroll" src="' +
								site.interUrl +
								'/js/jquery.nicescroll/jquery.nicescroll.min.js"></script>'
						);
					}
					$('.' + ranflag + ' .permission-container').niceScroll({
						cursorcolor: '#d9d9d9',
						cursorwidth: '8px',
						cursorborderradius: 0,
						cursorborder: 0
					});
					$('.' + ranflag + ' .permission-container .loadings').remove();
					showdata(data.menu[0], data.func);
					$('.' + ranflag + ' .permission-container').getNiceScroll().resize();
				} else {
					$('.' + ranflag + ' .permission-container').css({
						overflow: 'hidden',
						border: 'none'
					});
					$('.' + ranflag + ' .permission-container').html(
						'<div class="nodata"><img src="' + site.interUrl + '/img/nodata.png"><p>暂无数据</p></div>'
					);
				}
			} else {
				ly.toast('获取数据失败');
			}
		}
	});

	function showdata(menulist, funclist) {
		var $obj = $('.' + ranflag + ' .permission-container');
		for (var i = 1; i <= Object.keys(menulist).length; i++) {
			$.each(menulist['m' + i], function(j, item) {
				var ischosed = opts.echodataMenu.indexOf(item.id) == -1 ? '' : 'choosed open';
				if (opts.echodataMenu.length == 0 && opts.echodataFunc.length == 0 && opts.orgId) {
					ischosed = 'choosed open';
				}
				var exorzhan = opts.echodataMenu.indexOf(item.id) == -1 ? 'icon-expand' : 'icon-zhankai';
				var leaf = item.parentNum == 0 ? true : false;
				var _url = item.url ? '</label><label>url：' + item.url + '</label>' : '';
				var roots = i == 1 ? 'roots' : '';
				if (i != 1) {
					if ($('.' + ranflag + ' li[data-id=' + item.parentId + ']').next('ul.child-list').length == 0) {
						var s_h = $('.' + ranflag + ' li[data-id=' + item.parentId + ']').is('.open') ? '' : 'hide';
						$('.' + ranflag + ' li[data-id=' + item.parentId + ']').after(
							'<ul class="child-list ' + s_h + '"></ul>'
						);
					}
					$obj = $('.' + ranflag + ' li[data-id=' + item.parentId + ']').next('ul.child-list');
				}
				if (item.parentNum > 0) {
					$obj.append(
						'<li class="mens ' +
							roots +
							' ' +
							ischosed +
							'" data-id="' +
							item.id +
							'" isleaf="' +
							leaf +
							'"><i class="iconfont ' +
							exorzhan +
							'"></i><i class="iconfont icon-qiyong"></i>【菜单】<label class="pr10">' +
							item.menuName +
							'</li>'
					); //+ _url
				} else {
					// <i class="iconfont '+ exorzhan +'"></i>
					$obj.append(
						'<li class="mens ' +
							roots +
							' ' +
							ischosed +
							'" data-id="' +
							item.id +
							'" isleaf="' +
							leaf +
							'"><i class="iconfont icon-qiyong"></i>【菜单】<label class="pr10">' +
							item.menuName +
							'</li>'
					); //+ _url
				}
			});
		}
		$('.' + ranflag + ' .menus').text($('.' + ranflag + ' .mens.choosed').length);
		selectedOpts();
	}

	function selectedOpts() {
		$.each($('.' + ranflag + ' li.choosed'), function(i, item) {
			if ($(item).next('ul.child-list').length == 1) {
				if ($(item).next('ul').find('li').length != $(item).next('ul').find('li.choosed').length) {
					$(item).children('i.icon-qiyong').addClass('half-chos');
				}
			}
		});
	}
};

/**
 *	字典 单选/下拉
 */
$.fn.getSelect = function(options, callback) {
	// console.log(options)
	var dis = $(this).attr('disabled') == undefined ? false : true;
	var dft = $(this).attr('ly-val');
	var data = [];
	var obj = $(this),
		h = '',
		defaults = {
			label: '',
			type: 'select',
			asName: 'select',
			code: '',
			list: {},
			maxlength: '200',
			default: dft,
			disabled: dis,
			enable: []
		};
	var validate = {
		placeholder: $(this).attr('placeholder'),
		'data-tip': $(this).attr('data-tip'),
		'data-valid': $(this).attr('data-valid'),
		'data-error': $(this).attr('data-error')
	};
	var opts = $.extend({}, defaults, options);
	if ($(this).attr('id') == 's1') {
	}
	var s,
		d,
		list = {};
	obj.html('');
	if (opts.code != '') {
		request({
			url: site.dictionUrl,
			data: { code: opts.code },
			type: 'get',
			ajaxform: true,
			callback: function(d) {
				var e = d.result;
				h = '';
				list = $.grep(e, function(d) {
					return d.code == opts.code.split('|')[0];
				});
				if (opts.type == 'select') {
					h = "<option value=''>请选择</option>";
					if (opts.list.length > 0) {
						for (var i = 0; i < opts.list.length; i++) {
							s = opts.list[i].value == opts.default ? 'selected' : '';
							h +=
								'<option value="' +
								opts.list[i].value +
								'"  ' +
								s +
								'>' +
								opts.list[i].display +
								'</option>';
						}
					} else {
						for (var i = 0; i < list.length; i++) {
							var at = list[i].attr1 ? list[i].attr1 : '';
							s = list[i].value == opts.default ? 'selected' : '';
							h +=
								'<option nextcode="' +
								at +
								'" value="' +
								list[i].value +
								'"  ' +
								s +
								'>' +
								list[i].display +
								'</option>';
						}
					}
					obj.html(h);
				} else if (opts.type == 'radio') {
					for (var i = 0; i < opts.list.length; i++) {
						s = opts.list[i].value == opts.default ? 'checked' : '';
						d = opts.disabled ? 'disabled' : '';
						h +=
							'<label class="rad"><input type="radio" value="' +
							opts.list[i].value +
							'" name="' +
							opts.asName +
							'" ' +
							s +
							' ' +
							d +
							'><b></b>' +
							opts.list[i].display +
							'</label>';
					}
					for (var i = 0; i < list.length; i++) {
						s = list[i].value == opts.default ? 'checked' : '';
						d = opts.disabled ? 'disabled' : '';
						h +=
							'<label class="rad"><input type="radio" value="' +
							list[i].value +
							'" name="' +
							opts.asName +
							'" ' +
							s +
							' ' +
							d +
							'><b></b>' +
							list[i].display +
							'</label>';
					}
					obj.append(h);
				} else if (opts.type == 'checkbox') {
					var v;
					if (opts.default != '' && opts.default != undefined) {
						v = opts.default.split(',');
					} else {
						v = '';
					}
					for (var i = 0; i < opts.list.length; i++) {
						$.each(v, function(n, d) {
							if (d == opts.list[i].value) {
								s = 'checked';
								return false;
							} else {
								s = '';
							}
						});
						d = opts.disabled ? 'disabled' : '';
						h +=
							'<label class="chk"><input type="checkbox" value="' +
							opts.list[i].value +
							'" name="' +
							opts.asName +
							'" ' +
							s +
							' ' +
							d +
							'><b></b>' +
							opts.list[i].display +
							'</label>';
					}
					for (var i = 0; i < list.length; i++) {
						$.each(v, function(n, d) {
							if (d == list[i].value) {
								s = 'checked';
								return false;
							} else {
								s = '';
							}
						});
						d = opts.disabled ? 'disabled' : '';
						h +=
							'<label class="chk"><input type="checkbox" value="' +
							list[i].value +
							'" name="' +
							opts.asName +
							'" ' +
							s +
							' ' +
							d +
							'><b></b>' +
							list[i].display +
							'</label>';
					}
					obj.append(h);
				} else if (opts.type == 'screen') {
					d = opts.disabled ? 'disabled' : '';
					h += '<div class="label">' + opts.label + '</div><ul class="screen">';
					if (d == '') {
						h +=
							'<li><label><input name="' +
							opts.asName +
							'" type="radio" checked value =""><b>全部</b></label></li>';
					}
					for (var i = 0; i < opts.list.length; i++) {
						s = opts.list[i].value == opts.default ? 'checked' : '';
						h +=
							'<li><label><input name="' +
							opts.asName +
							'" type="radio" ' +
							s +
							' ' +
							(d && opts.enable.length > 0 && opts.enable.indexOf(opts.list[i].value) > -1 ? '' : d) +
							' value = "' +
							opts.list[i].value +
							'"><b>' +
							opts.list[i].display +
							'</b></label></li>';
					}
					for (var i = 0; i < list.length; i++) {
						s = list[i].value == opts.default ? 'checked' : '';
						h +=
							'<li><label><input name="' +
							opts.asName +
							'" type="radio" ' +
							s +
							' ' +
							(d && opts.enable.length > 0 && opts.enable.indexOf(list[i].value) > -1 ? '' : d) +
							' value = "' +
							list[i].value +
							'"><b>' +
							list[i].display +
							'</b></label></li>';
					}
					h += '</ul>';
					obj.append(h);
				}
				if (typeof callback == 'function') {
					callback(obj);
				}
			}
		});
	} else {
		if (opts.type == 'select') {
			for (var i = 0; i < opts.list.length; i++) {
				var at = opts.list[i].attr1 ? opts.list[i].attr1 : '';
				s = opts.list[i].value == opts.default ? 'selected' : '';
				h += '<option value="' + opts.list[i].value + '"  ' + s + '>' + opts.list[i].display + '</option>';
			}
			obj.html(h);
		} else if (opts.type == 'radio') {
			for (var i = 0; i < opts.list.length; i++) {
				s = opts.list[i].value == opts.default ? 'checked' : '';
				d = opts.disabled ? 'disabled' : '';
				h +=
					'<label class="rad"><input type="radio" value="' +
					opts.list[i].value +
					'" name="' +
					opts.asName +
					'" ' +
					s +
					' ' +
					d +
					'><b></b>' +
					opts.list[i].display +
					'</label>';
			}
			obj.append(h);
		} else if (opts.type == 'checkbox') {
			var v;
			if (opts.default != '' && opts.default != undefined) {
				v = opts.default.split(',');
			} else {
				v = '';
			}
			for (var i = 0; i < opts.list.length; i++) {
				$.each(v, function(n, d) {
					if (d == opts.list[i].value) {
						s = 'checked';
						return false;
					} else {
						s = '';
					}
				});
				d = opts.disabled ? 'disabled' : '';
				if (opts.list[i].disabled) {
					d = 'disabled';
				}
				h +=
					'<label class="chk"><input type="checkbox" value="' +
					opts.list[i].value +
					'" name="' +
					opts.asName +
					'" ' +
					s +
					' ' +
					d +
					'><b></b>' +
					opts.list[i].display +
					'</label>';
			}
			obj.append(h);
		} else if (opts.type == 'screen') {
			d = opts.disabled ? 'disabled' : '';
			h += '<div class="label">' + opts.label + '</div><ul class="screen">';
			if (d == '') {
				h +=
					'<li><label><input name="' +
					opts.asName +
					'" type="radio" checked value =""><b>全部</b></label></li>';
			}
			for (var i = 0; i < opts.list.length; i++) {
				s = opts.list[i].value == opts.default ? 'checked' : '';
				h +=
					'<li><label><input name="' +
					opts.asName +
					'" type="radio" ' +
					s +
					' ' +
					d +
					' value = "' +
					opts.list[i].value +
					'"><b>' +
					opts.list[i].display +
					'</b></label></li>';
			}
			h += '</ul>';
			obj.append(h);
		}
		if (typeof callback == 'function') {
			callback(obj);
		}
	}
};
/**
 *	根据字典创造筛选条件
 */
$('[ly-type=screen]').each(function() {
	var label = $(this).attr('label');
	var name = $(this).attr('name');
	$(this).removeAttr('name');
	var code = $(this).attr('ly-code');
	var type = 'screen';
	$(this).getSelect({
		label: label,
		type: 'screen',
		asName: name,
		code: code
	});
});
function disp(t) {
	if (t == '' || t == 'true' || t == undefined) {
		return '';
	} else if (t == 'false') {
		return 'none';
	}
}
//格式化日期（date，reg）
function dateFormat(now, mask) {
	if (mask == null || mask == '' || mask == undefined) {
		mask = 'yyyy-MM-dd HH:mm:ss';
	}
	var d = now;
	if (now instanceof Date) {
		d = now;
	} else {
		now = now.replace(/-/g, '/');
		d = new Date(now);
	}
	var zeroize = function(value, length) {
		if (!length) length = 2;
		value = String(value);
		for (var i = 0, zeros = ''; i < length - value.length; i++) {
			zeros += '0';
		}
		return zeros + value;
	};

	return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function($0) {
		switch ($0) {
			case 'd':
				return d.getDate();
			case 'dd':
				return zeroize(d.getDate());
			case 'ddd':
				return [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat' ][d.getDay()];
			case 'dddd':
				return [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ][d.getDay()];
			case 'M':
				return d.getMonth() + 1;
			case 'MM':
				return zeroize(d.getMonth() + 1);
			case 'MMM':
				return [
					'Jan',
					'Feb',
					'Mar',
					'Apr',
					'May',
					'Jun',
					'Jul',
					'Aug',
					'Sep',
					'Oct',
					'Nov',
					'Dec'
				][d.getMonth()];
			case 'MMMM':
				return [
					'January',
					'February',
					'March',
					'April',
					'May',
					'June',
					'July',
					'August',
					'September',
					'October',
					'November',
					'December'
				][d.getMonth()];
			case 'yy':
				return String(d.getFullYear()).substr(2);
			case 'yyyy':
				return d.getFullYear();
			case 'h':
				return d.getHours() % 12 || 12;
			case 'hh':
				return zeroize(d.getHours() % 12 || 12);
			case 'H':
				return d.getHours();
			case 'HH':
				return zeroize(d.getHours());
			case 'm':
				return d.getMinutes();
			case 'mm':
				return zeroize(d.getMinutes());
			case 's':
				return d.getSeconds();
			case 'ss':
				return zeroize(d.getSeconds());
			case 'l':
				return zeroize(d.getMilliseconds(), 3);
			case 'L':
				var m = d.getMilliseconds();
				if (m > 99) m = Math.round(m / 10);
				return zeroize(m);
			case 'tt':
				return d.getHours() < 12 ? 'am' : 'pm';
			case 'TT':
				return d.getHours() < 12 ? 'AM' : 'PM';
			case 'Z':
				return d.toUTCString().match(/[A-Z]+$/);
			default:
				return $0.substr(1, $0.length - 2);
		}
	});
}

/**
 *	验证表单
 */
$('div.validform').each(function() {
	if ($('#valid').length < 1) {
		$('body').append('<script id="valid" src="' + site.interUrl + '/js/jquery-validate.js"></script>');
	}
});
/**
 *  组合对象
 */
function getter(obj, path) {
	//obj：节点名,path：对象组合
	if (!path) return obj;
	var keys = path.split('.');
	var key;
	var lastInstance = obj;
	var len = keys.length;
	for (var i = 0; i < len; i++) {
		key = keys[i];
		if (obj) {
			obj = (lastInstance = obj)[key];
		}
	}
	return obj;
}
/**
 *  json键名替换
 */
var jsonArrangement = function(j, n, nn) {
	n = n.split('|');
	nn = nn.split('|');
	$.each(j, function(i, d) {
		$.each(n, function(j, e) {
			var t = d[e];
			delete d[e];
			d[nn[j]] = t;
		});
	});
	return j;
};
/**
 *  获得唯一字符串
 */
var Uniquestring = function(v) {
	var d = new Date().getTime();
	var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
		var r = ((d + Math.random() * 16) % 16) | 0;
		d = Math.floor(d / 16);
		return (c == 'x' ? r : (r & 0x3) | 0x8).toString(16);
	});
	return v + uuid;
};
/**
 *  文本框单位
 */
var showUnit = function() {
	$('[unit]').each(function() {
		var _this = $(this);
		_this.next('.unit').remove();
		_this.css('padding-right', '0');
		var u = _this.attr('unit');
		if (_this.parent().css('position') != 'absolute' && !_this.parents().css('position') != 'fixed') {
			_this.parent().css({
				position: 'relative',
				'font-size': '0'
			});
		}
		if (_this.siblings('.unit').length == 0 && _this.attr('ly-type') != 'text') {
			_this.before('<span class="unit">' + u + '</span>');
		}
	});
};
showUnit();

/**
 *  去html格式，并截取长度
 */
var abstract = function(e, n) {
	var e = e || '';
	if (e) {
		var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
		var t = e.replace(regexp, '');
		if (t.length > n) {
			return t.substring(0, n) + '...';
		} else {
			return t;
		}
	}
};

var comolete = false;
var lyComplete = function() {
	setDateinput(); //生成日期选择器
	showUnit(); //显示单位
	addGutter(); //间距处理
	setVideoUploader();
	iconSelector();
	comolete = true;
};
addGutter();

var stopBubble = function(e) {
	if (e && e.stopPropagation) {
		e.stopPropagation();
	} else {
		window.event.cancelBubble = true;
		return false;
	}
};

// 单点地图选择器
$.fn.singleMapSelector = function(options, callback) {
	var _this = $(this);
	var inInfo = '',
		code = '';
	if (_this.attr('type') != 'btnMap' && _this.attr('type') != 'inputMap') {
		return;
	}
	if (options) {
		if (options.code) {
			code = options.code;
		}
		inInfo = JSON.stringify(options);
	}
	_this.unbind('click');
	if (_this.attr('type') == 'btnMap') {
		_this.click(function() {
			_this
				.parents('body')
				.prepend(
					'<iframe class="showMapSelector-iframe" ininfo=\'' +
						inInfo +
						'\' style="width:100%;height:100%;position:fixed;top: 0;left: 0;z-index:9999;" src="' +
						site.interUrl +
						'/js/mapSelector/showmap.html" frameborder="0"></iframe>'
				);
			var $obj = _this.parents('body').find('.showMapSelector-iframe');
			$obj[0].onload = function() {
				var $thisDom = $(this.contentWindow.document);
				//关闭弹窗
				$thisDom.find('.header .icon-close').on('click', function() {
					$obj.remove();
					return;
				});
			};
		});
	} else {
		_this.click(function() {
			_this
				.parents('body')
				.prepend(
					'<iframe class="singleMapSelector-iframe" ininfo=\'' +
						inInfo +
						'\' style="width:100%;height:100%;position:fixed;top: 0;left: 0;z-index:9999;" src="' +
						site.interUrl +
						'/js/mapSelector/single.html" frameborder="0"></iframe>'
				);
			var $obj = _this.parents('body').find('.singleMapSelector-iframe');
			$obj[0].onload = function() {
				var $thisDom = $(this.contentWindow.document);
				//关闭弹窗
				$thisDom.find('.btnBox .btn-return').on('click', function() {
					$obj.remove();
					return;
				});
				//提交数据
				$thisDom.find('.btnBox').on('click', '.btn-submit.submit', function() {
					$thisDom.find('.tip input').animate({ width: '0px', paddingLeft: '0px', paddingRight: '0px' }, 10);
					$thisDom.find('.tip span').addClass('none');
					$thisDom.find('.btn-submit').addClass('editAdd').removeClass('submit');
					var addressInfo = $obj.data('outInfo');
					if (!addressInfo) {
						addressInfo = $obj.attr('ininfo');
					}
					var data = JSON.parse(addressInfo);
					data.address = $thisDom.find('.tip input').val();
					if (_this.attr('type') == 'inputMap') {
						if (typeof callback == 'function') {
							callback(data);
							$thisDom.find('.btnBox .btn-return').click();
						}
					} else if (_this.attr('type') == 'btnMap') {
					}
				});
			};
		});
	}
};

//icon选择器
function iconSelector() {
	$('input[type=icon]').each(function(e) {
		if ($('#selector').length < 1) {
			$('#ly_main_js').before('<script id="selector" src="' + site.interUrl + '/js/selector.js"></script>');
		}
		$(this).next('.icon_selector').remove();
		var select = '<div class="icon_selector">';
		select += '<div class="selector_pop">';
		select += '<span class="selected">';
		select += '<i class="iconfont-guangming" title="" icontit=""></i>';
		select += '</span>';
		select += '<span class="selector_button">';
		select += '<i class="iconfont-guangming icon-xiala" title="icon-xiala" icontit=""></i>';
		select += ' </span>';
		select += '</div>';
		select += '<div class="selectort" style="display: none">';
		select +=
			'<input type="text"  name="" value="" placeholder="搜索图标" class="selector_find" id="selecticonid' +
			e +
			'"  ">';
		select += '<span class="selected-icon">';
		select += '</span>';
		select += '</div>';
		select += '</div>';
		var _this = $(this);
		_this.hide();
		_this.after(select);
		var v = _this.val();
		var icontype = _this.attr('icontype');
		if (icontype) {
			$('.selected').html('<i class="iconfont-guangming" title="' + v + '" iconcode="' + v + '"> ' + v + '</i>');
		} else {
			$('.selected').html('<i class="iconfont-guangming ' + v + '" title="' + v + ' "></i>');
		}

		var data;
		var url = site.interUrl + '/js/json/icon.json';
		var ht = '<span class="l_box"><i class="" title="" icontit=""></i></span>';
		request({
			url: url,
			data: data,
			type: 'get',
			callback: function(e) {
				for (var i = 0; i < e.list.length; i++) {
					ht +=
						'<span class="l_box"><i class="iconfont-guangming ' +
						e.list[i]['name'] +
						'" title="' +
						e.list[i]['name'] +
						'" iconCode="' +
						e.list[i]['code'] +
						'" icontit="' +
						e.list[i]['cnname'] +
						'"></i></span>';
				}
				$('.selected-icon').append(ht);
			}
		});
		$('#selecticonid' + e + '').on('keyup', function() {
			var ival = $(this).val();
			var py = makePy(ival);
			var lower = py[0].toLowerCase();
			$('.selected-icon span').each(function(s) {
				var icontitle = $(this).children('i').attr('icontit');
				var newPY = makePy(icontitle)[0].toLowerCase();
				if (newPY.indexOf(lower) < 0 && icontitle.indexOf(lower) < 0) {
					$(this).hide();
				} else {
					$(this).show();
				}
			});
		});
		var se = $('.selector_button');
		se.click(function() {
			$('.selectort').toggle(100);
		});
		$('.selected-icon').on('click', '.l_box', function() {
			$('.selected').html($(this).html());
			if (icontype) {
				_this.val($(this).find('.iconfont-guangming').attr('iconcode'));
			} else {
				_this.val($(this).find('.iconfont-guangming').attr('title'));
			}

			$('.selectort').hide(100);
			_this.blur();
		});
		$('body').on('click', function(e) {
			var target = $(e.target);
			if (target.closest('.selector_pop').length == 0 && target.closest('.selectort').length == 0) {
				$('.selectort').hide(100);
			}
		});
	});
}

function imgerror(ev) {
	$(ev).attr('src', '../../img/default_head.jpg');
}
/*时间戳转换*/
function formatDate(times) {
	/*时间渲染*/
	function add(m) {
		return m < 10 ? '0' + m : m;
	}
	var time = new Date(times);
	var y = time.getFullYear();
	var m = time.getMonth() + 1;
	var d = time.getDate();
	var h = time.getHours();
	var mm = time.getMinutes();
	var s = time.getSeconds();
	return y + '-' + add(m) + '-' + add(d) + ' ' + add(h) + ':' + add(mm);
}
//获得月份差值
function monthMinus(sDate, eDate) {
	var sdate = new Date(sDate.replace(/-/g, '/'));
	var edate = new Date(eDate.replace(/-/g, '/'));
	var month = edate.getFullYear() * 12 + edate.getMonth() - (sdate.getFullYear() * 12 + sdate.getMonth());
	return month;
}
//获得日差值
function DateMinus(sDate, eDate) {
	var sdate = new Date(sDate.replace(/-/g, '/'));
	var edate = new Date(eDate.replace(/-/g, '/'));
	var days = edate.getTime() - sdate.getTime();
	var day = parseInt(days / (1000 * 60 * 60 * 24));
	return day;
}
